#include "Model_Head.h"						//< 各SAMA文件头文件集合
#include "../Global_Func/Ftp/Ftp_Diy.h"
/*SAMA部分全局变量*/
bool SAMA_PageBCFlag[SAMA_PGE_MAX];					//< 相应页的SAMA模块广播参数（true：广播；false：不广播）
int Model_TotalNum;									//< SAMA模块总数量（除了文本模块、页与页之间切换用的模块之外的所有需要下位运算的模块的总数）
BCSamaPara_Set_t BCSamaPara_Set;					//< 广播SAMA参数标志位
int Model_Calcu_Type[SAMA_MODEL_MAXNUM];			//< SAMA模块运算排序之存储类型的数组
unsigned int Model_Calcu_ID[SAMA_MODEL_MAXNUM];		//< SAMA模块运算排序之存储模块ID号的数组
int NumOf_Sama_Type[TYP_MAX_MODEL];					//< 各类SAMA模块的数量
int Model_Type_Map[TYP_MAX_UP];						//< 该数组存放了上下位模块类型号的映射关系，上位中模块的类型号通过该数组关系转化为下位中类型号使用，未使用的模块初始化为-1
bool BCIODataFlg;									//< 广播数据库IO点（软点+硬点）标志


//************************************
// Method:    	Model_Type_Map_Init			SAMA模块上下位模块号映射关系初始化函数
// Programmer:  lww
// Time:		2018/12/19
// Returns:   	void
//************************************
void Model_Type_Map_Init()
{
	memset(Model_Type_Map, -1, sizeof(Model_Type_Map));

	//< 自定义算法模块
	Model_Type_Map[TYP_USERDEF_UP] = TYP_USERDEF;

	//< 信号源模块
	Model_Type_Map[TYP_STEP_UP] = TYP_STEP;
	Model_Type_Map[TYP_RAMP_UP] = TYP_RAMP;
	Model_Type_Map[TYP_SINSOURCE_UP] = TYP_SINSOURCE;
	Model_Type_Map[TYP_SQUA_UP] = TYP_SQUA;
	Model_Type_Map[TYP_SAW_UP] = TYP_SAW;
	Model_Type_Map[TYP_BROK_UP] = TYP_BROK;
	Model_Type_Map[TYP_MSQUA_UP] = TYP_MSQUA;
	Model_Type_Map[TYP_RAND_UP] = TYP_RAND;
	Model_Type_Map[TYP_PRBS_UP] = TYP_PRBS;
	Model_Type_Map[TYP_FIXPULSE_UP] = TYP_FIXPULSE;
	Model_Type_Map[TYP_SETSTEP_UP] = TYP_SETSTEP;

	//< 数学运算模块
	Model_Type_Map[TYP_ADD_UP] = TYP_ADD;
	Model_Type_Map[TYP_SUB_UP] = TYP_SUB;
	Model_Type_Map[TYP_MUL_UP] = TYP_MUL;
	Model_Type_Map[TYP_DIV_UP] = TYP_DIV;
	Model_Type_Map[TYP_SQUAROOT_UP] = TYP_SQUAROOT;
	Model_Type_Map[TYP_ABS_UP] = TYP_ABS;
	Model_Type_Map[TYP_EXP_UP] = TYP_EXP;
	Model_Type_Map[TYP_POW_UP] = TYP_POW;
	Model_Type_Map[TYP_LOG_UP] = TYP_LOG;
	Model_Type_Map[TYP_SIN_UP] = TYP_SIN;
	Model_Type_Map[TYP_ASIN_UP] = TYP_ASIN;
	Model_Type_Map[TYP_MATHS_UP] = TYP_MATHS;
	Model_Type_Map[TYP_ENTHALPY_UP] = TYP_ENTHALPY;
	Model_Type_Map[TYP_TS_UP] = TYP_TS;
	Model_Type_Map[TYP_ATTRATE_UP] = TYP_ATTRATE;
	//< 输入输出模块
	Model_Type_Map[TYP_AI_UP] = TYP_AI;
	Model_Type_Map[TYP_AO_UP] = TYP_AO;
	Model_Type_Map[TYP_DI_UP] = TYP_DI;
	Model_Type_Map[TYP_DO_UP] = TYP_DO;
	Model_Type_Map[TYP_NETAI_UP] = TYP_NETAI;
	Model_Type_Map[TYP_NETAO_UP] = TYP_NETAO;
	Model_Type_Map[TYP_NETDI_UP] = TYP_NETDI;
	Model_Type_Map[TYP_NETDO_UP] = TYP_NETDO;
	Model_Type_Map[TYP_AIGetFile_UP] = TYP_AIGetFile;
	Model_Type_Map[TYP_FW_UP] = TYP_FW;
	Model_Type_Map[TYP_FR_UP] = TYP_FR;

	//< 逻辑运算模块
	Model_Type_Map[TYP_AND_UP] = TYP_AND;
	Model_Type_Map[TYP_OR_UP] = TYP_OR;
	Model_Type_Map[TYP_NOT_UP] = TYP_NOT;
	Model_Type_Map[TYP_XOR_UP] = TYP_XOR;
	Model_Type_Map[TYP_SIGN_UP] = TYP_SIGN;
	Model_Type_Map[TYP_RSTRIG_UP] = TYP_RSTRIG;
	Model_Type_Map[TYP_DTRIG_UP] = TYP_DTRIG;
	Model_Type_Map[TYP_COUNT_UP] = TYP_COUNT;
	Model_Type_Map[TYP_COMPA_UP] = TYP_COMPA;
	Model_Type_Map[TYP_ALM_UP] = TYP_ALM;
	Model_Type_Map[TYP_IN16OUT1_UP] = TYP_IN16OUT1;
	Model_Type_Map[TYP_IN1OUT16_UP] = TYP_IN1OUT16;
	Model_Type_Map[TYP_DTOA_UP] = TYP_DTOA;
	Model_Type_Map[TYP_CONJUDE_UP] = TYP_CONJUDE;
	Model_Type_Map[TYP_IN1OUT32_UP] = TYP_IN1OUT32;

	//< 选择模块
	Model_Type_Map[TYP_AISEL_UP] = TYP_AISEL;
	Model_Type_Map[TYP_AOSEL_UP] = TYP_AOSEL;
	Model_Type_Map[TYP_DISEL_UP] = TYP_DISEL;
	Model_Type_Map[TYP_DOSEL_UP] = TYP_DOSEL;
	Model_Type_Map[TYP_MIDSEL_UP] = TYP_MIDSEL;
	Model_Type_Map[TYP_MAXSEL_UP] = TYP_MAXSEL;
	Model_Type_Map[TYP_MINSEL_UP] = TYP_MINSEL;
	Model_Type_Map[TYP_DG2OF3_UP] = TYP_DG2OF3;

	//< 控制算法模块
	Model_Type_Map[TYP_PID_UP] = TYP_PID;
	Model_Type_Map[TYP_AManSta_UP] = TYP_AManSta;
	Model_Type_Map[TYP_DManSta_UP] = TYP_DManSta;
	Model_Type_Map[TYP_ASET_UP] = TYP_ASET;
	Model_Type_Map[TYP_DSET_UP] = TYP_DSET;
	Model_Type_Map[TYP_LeadLag_UP] = TYP_LeadLag;
	Model_Type_Map[TYP_StepCont_UP] = TYP_StepCont;
	Model_Type_Map[TYP_In8Bala_UP] = TYP_In8Bala;
	Model_Type_Map[TYP_In2Bala_UP] = TYP_In2Bala;
	Model_Type_Map[TYP_Trans2_UP] = TYP_Trans2;
	Model_Type_Map[TYP_Trans3_UP] = TYP_Trans3;
	Model_Type_Map[TYP_DEVICE_UP] = TYP_DEVICE;
	Model_Type_Map[TYP_StimuSigCon_UP] = TYP_StimuSigCon;
	Model_Type_Map[TYP_DMC_UP] = TYP_DMC;
	Model_Type_Map[TYP_DstrbOn_UP] = TYP_DstrbOn;
	Model_Type_Map[TYP_FFDMC_UP] = TYP_FFDMC;

	//< 时间算法模块
	Model_Type_Map[TYP_TIMER_UP] = TYP_TIMER;
	Model_Type_Map[TYP_CYCTIMER_UP] = TYP_CYCTIMER;
	Model_Type_Map[TYP_TOTAL_UP] = TYP_TOTAL;
	Model_Type_Map[TYP_TIMEGET_UP] = TYP_TIMEGET;
	Model_Type_Map[TYP_STACK_UP] = TYP_STACK;
	Model_Type_Map[TYP_PUL_UP] = TYP_PUL;
	Model_Type_Map[TYP_DELAYON_UP] = TYP_DELAYON;
	Model_Type_Map[TYP_DELAYOFF_UP] = TYP_DELAYOFF;

	//< 线性算法模块
	Model_Type_Map[TYP_CONST_UP] = TYP_CONST;
	Model_Type_Map[TYP_DELAY_UP] = TYP_DELAY;
	Model_Type_Map[TYP_INTEG_UP] = TYP_INTEG;
	Model_Type_Map[TYP_DIFFE_UP] = TYP_DIFFE;
	Model_Type_Map[TYP_CTF1_UP] = TYP_CTF1;
	Model_Type_Map[TYP_CTF2_UP] = TYP_CTF2;
	Model_Type_Map[TYP_DTF_UP] = TYP_DTF;
	Model_Type_Map[TYP_DISUM_UP] = TYP_DISUM;

	//< 非线性算法模块
	Model_Type_Map[TYP_RANGE_UP] = TYP_RANGE;
	Model_Type_Map[TYP_RANGEALM_UP] = TYP_RANGEALM;
	Model_Type_Map[TYP_RATE_UP] = TYP_RATE;
	Model_Type_Map[TYP_RATEALM_UP] = TYP_RATEALM;
	Model_Type_Map[TYP_DEAD_UP] = TYP_DEAD;
	Model_Type_Map[TYP_SWITCH_UP] = TYP_SWITCH;
	Model_Type_Map[TYP_GEARBL_UP] = TYP_GEARBL;
	Model_Type_Map[TYP_HYLOOP_UP] = TYP_HYLOOP;
	Model_Type_Map[TYP_MAGAMP_UP] = TYP_MAGAMP;
	Model_Type_Map[TYP_MLINE_UP] = TYP_MLINE;

	//< 设备驱动模块

}


/*SAMA模块链表私有参数数组（严格按照.h文件中SAMA模块类型枚举顺序）*/
Model_List_Par_t Model_List_Par[TYP_MAX_MODEL] =
{

	//< 自定义算法模块
	//{ BAK_ATTEND, NULL },
	//{ BAK_ATTEND, ATTEND_PARA(USERDEF) },
	{BAK_STA, NULL},

	/*信号源模块枚举		SignalSource_Model*/
	{ BAK_STA, NULL },					//< 阶跃信号模块
	{ BAK_STA, NULL },					//< 斜坡信号模块
	{ BAK_STA, NULL },					//< 斜坡信号模块
	{ BAK_STA, NULL },					//< 方波信号模块
	{ BAK_STA, NULL },					//< 锯齿波信号模块
	{ BAK_STA, NULL },					//< 折线信号模块
	{ BAK_STA, NULL },					//< 多段方波信号模块
	{ BAK_NON, NULL },					//< 随机信号模块
	{ BAK_STA, NULL },					//< 伪随机序列信号模块
	{ BAK_STA, NULL },                  //< 固定脉冲信号模块
	{ BAK_STA, NULL },                  //< 设定值阶跃扰动模块

	/*数学运算模块枚举		Math_Model*/
	{ BAK_NON, NULL },					//< 加法模块
	{ BAK_NON, NULL },					//< 减法模块
	{ BAK_NON, NULL },					//< 乘法模块
	{ BAK_NON, NULL },					//< 除法模块
	{ BAK_NON, NULL },					//< 平方根模块
	{ BAK_NON, NULL },					//< 绝对值模块
	{ BAK_NON, NULL },					//< 指数模块
	{ BAK_NON, NULL },					//< 幂函数模块
	{ BAK_NON, NULL },					//< 对数模块
	{ BAK_NON, NULL },					//< 三角函数模块
	{ BAK_NON, NULL },					//< 反三角函数模块
	{ BAK_NON, NULL },					//< 多项式模块
	{ BAK_NON, NULL },					//< 焓值计算模块		
	{ BAK_NON, NULL },                  //< 调整时间Ts指标计算模块  
	{ BAK_NON, NULL },                  //< 衰减率指标计算模块

	/*输入输出模块枚举		IO_Model*/
	{ BAK_NON, NULL },					//< 模拟量输入模块
	{ BAK_NON, NULL },					//< 模拟量输出模块
	{ BAK_NON, NULL },					//< 开关量输入模块
	{ BAK_NON, NULL },					//< 开关量输出模块
	{ BAK_STA, NULL },					//< 站间通讯模拟量输入模块
	{ BAK_NON, NULL },					//< 站间通讯模拟量输出模块
	{ BAK_STA, NULL },					//< 站间通讯数字量输入模块
	{ BAK_NON, NULL },					//< 站间通讯数字量输出模块	
	{ BAK_NON, NULL },					//< 数据采集模块
	{ BAK_STA, NULL },					//< 文件写入数据模块
	{ BAK_STA, NULL },					//< 文件读取数据模块

	/*逻辑运算模块枚举		Logic_Model*/
	{ BAK_NON, NULL },					//< 逻辑“与”模块
	{ BAK_NON, NULL },					//< 逻辑“或”模块
	{ BAK_NON, NULL },					//< 逻辑“非”模块
	{ BAK_NON, NULL },					//< 逻辑“异或”模块
	{ BAK_NON, NULL },					//< 符号判断模块
	{ BAK_NON, NULL },					//< RS触发器模块
	{ BAK_STA, NULL },					//< D触发器模块
	{ BAK_STA, NULL },					//< 计数器模块
	{ BAK_NON, NULL },					//< 比较器模块
	{ BAK_NON, NULL },					//< 偏差报警模块
	{ BAK_NON, NULL },					//< 16-1模块
	{ BAK_NON, NULL },					//< 1-16模块
	{ BAK_NON, NULL },					//< 数字量to模拟量模块
	{ BAK_NON, NULL },                  //< 控制性能综合判断模块
	{ BAK_NON, NULL },					//< 1-32模块

	/*选择模块枚举			Choice_Model*/
	{ BAK_STA, NULL },					//< 模拟量输入选择模块
	{ BAK_STA, NULL },					//< 模拟量输出选择模块
	{ BAK_NON, NULL },					//< 数字量输入选择模块
	{ BAK_NON, NULL },					//< 数字量输出选择模块
	{ BAK_NON, NULL },					//< 中间值选择模块
	{ BAK_NON, NULL },					//< 最大值选择模块
	{ BAK_NON, NULL },					//< 最小值选择模块
	{ BAK_NON, NULL },					//< 数字信号3选2模块
	

	/*控制算法模块枚举		Control_Model*/
	{ BAK_STA, NULL },					//< PID控制模块
	{ BAK_STA, NULL },					//< 模拟手动站模块
	{ BAK_STA, NULL },					//< 数字手动站模块
	{ BAK_STA, NULL },					//< 模拟量给定值发生器模块
	{ BAK_STA, NULL },					//< 数字量给定值发生器模块
	{ BAK_STA, NULL },					//< 超前滞后模块
	{ BAK_STA, NULL },					//< 步序控制模块
	{ BAK_STA, NULL },					//< 输入平衡模块（8IB）
	{ BAK_NON, NULL },					//< 输入平衡模块（2IB）
	{ BAK_STA, NULL },					//< 两变送器整合模块
	{ BAK_STA, NULL },					//< 三变送器整合模块
	{ BAK_STA, NULL },					//< 设备驱动模块
	{ BAK_STA, NULL },					//< 激励信号启停模块
	{ BAK_NON, NULL },					//< DMC模块
	{ BAK_STA, NULL },					//< 扰动启动模块
	{ BAK_NON, NULL },					//< FFDMC模块

	/*时间算法模块枚举		Time_Model*/
	{ BAK_STA, NULL },					//< 定时器模块
	{ BAK_NON, NULL },					//< 周期定时器模块
	{ BAK_STA, NULL },					//< 积算器模块
	{ BAK_NON, NULL },					//< 时间获取模块
	{ BAK_STA, NULL },					//< 数据堆栈模块
	{ BAK_STA, NULL },					//< 脉冲模块
	{ BAK_STA, NULL },					//< 延时开模块
	{ BAK_STA, NULL },					//< 延时关模块

	/*线性算法模块枚举		Line_Model*/
	{ BAK_NON, NULL },					//< 常系数模块
	{ BAK_STA, NULL },					//< 纯迟延模块
	{ BAK_STA, NULL },					//< 积分模块
	{ BAK_STA, NULL },					//< 微分模块
	{ BAK_STA, NULL },					//< 连续传递函数1模块
	{ BAK_STA, NULL },					//< 连续传递函数2模块
	{ BAK_STA, NULL },					//< 离散传递函数2模块
	{ BAK_STA, NULL },					//< 数字信号加法器功能块 

	/*非线性算法模块枚举	NonLine_Model*/
	{ BAK_NON, NULL },					//< 限幅模块
	{ BAK_STA, NULL },					//< 幅值报警模块
	{ BAK_STA, NULL },					//< 速率限制模块
	{ BAK_STA, NULL },					//< 速率报警模块
	{ BAK_NON, NULL },					//< 死区模块
	{ BAK_NON, NULL },					//< 开关模块
	{ BAK_STA, NULL },					//< 齿轮间隙模块
	{ BAK_STA, NULL },					//< 滞环开关模块
	{ BAK_STA, NULL },					//< 磁放模块
	{ BAK_NON, NULL },					//< 分段线性模块
	

	/*设备驱动模块枚举		DeviceDriver_Model*/


	/*自定义算法模块枚举	UserDefined_Model*/

	
};


/*SAMA模块链表私有函数数组（严格按照.h文件中SAMA模块类型枚举顺序）*/
Model_List_Func_t Model_List_Func[TYP_MAX_MODEL] = 
{
	/*自定义算法模块枚举	UserDefined_Model*/
	{ CALCU_SAMA(USERDEF), BC_PARA(USERDEF), CHANGE_PAR(USERDEF), BAK_STA(USERDEF), ANA_STA(USERDEF), INIT_STAPAR(USERDEF), NULL },

	/*信号源模块枚举		SignalSource_Model*/
	{ CALCU_SAMA(STEP), BC_PARA(STEP), CHANGE_PAR(STEP), BAK_STA(STEP), ANA_STA(STEP), INIT_STAPAR(STEP), NULL },									//< 阶跃信号模块
	{ CALCU_SAMA(RAMP), BC_PARA(RAMP),  CHANGE_PAR(RAMP),BAK_STA(RAMP), ANA_STA(RAMP), INIT_STAPAR(RAMP), NULL },									//< 斜坡信号模块
	{ CALCU_SAMA(SINSOURCE), BC_PARA(SINSOURCE), CHANGE_PAR(SINSOURCE),BAK_STA(SINSOURCE), ANA_STA(SINSOURCE),  INIT_STAPAR(SINSOURCE), NULL },		//< 正弦信号模块
	{ CALCU_SAMA(SQUA), BC_PARA(SQUA), CHANGE_PAR(SQUA), BAK_STA(SQUA), ANA_STA(SQUA), INIT_STAPAR(SQUA), NULL },									//< 方波信号模块
	{ CALCU_SAMA(SAW), BC_PARA(SAW),CHANGE_PAR(SAW), BAK_STA(SAW), ANA_STA(SAW), INIT_STAPAR(SAW), NULL },											//< 锯齿波信号模块
	{ CALCU_SAMA(BROK), BC_PARA(BROK), CHANGE_PAR(BROK),BAK_STA(BROK), ANA_STA(BROK), INIT_STAPAR(BROK), NULL },									//< 折线波信号模块 
	{ CALCU_SAMA(MSQUA), BC_PARA(MSQUA),CHANGE_PAR(MSQUA), BAK_STA(MSQUA), ANA_STA(MSQUA),  INIT_STAPAR(MSQUA), NULL },								//< 多段方波信号模块  
	{ CALCU_SAMA(RAND), BC_PARA(RAND), CHANGE_PAR(RAND),NULL, NULL, NULL, NULL },																	//< 随机信号模块  
	{ CALCU_SAMA(PRBS), BC_PARA(PRBS),CHANGE_PAR(PRBS), BAK_STA(PRBS), ANA_STA(PRBS),INIT_STAPAR(PRBS), NULL },										//< 伪随机序列信号模块
	{ CALCU_SAMA(FIXPULSE), BC_PARA(FIXPULSE),CHANGE_PAR(FIXPULSE), BAK_STA(FIXPULSE), ANA_STA(FIXPULSE),  INIT_STAPAR(FIXPULSE), NULL },			//< 固定脉冲信号模块  
	{ CALCU_SAMA(SETSTEP), BC_PARA(SETSTEP),CHANGE_PAR(SETSTEP), BAK_STA(SETSTEP), ANA_STA(SETSTEP),  INIT_STAPAR(SETSTEP), NULL },			        //< 设定值阶跃扰动模块  

	/*数学运算模块枚举		Math_Model*/
	{ CALCU_SAMA(ADD), BC_PARA(ADD), CHANGE_PAR(ADD), NULL, NULL, NULL, NULL },												//< 加法模块
	{ CALCU_SAMA(SUB), BC_PARA(SUB), CHANGE_PAR(SUB), NULL, NULL, NULL, NULL },												//< 减法模块
	{ CALCU_SAMA(MUL), BC_PARA(MUL), CHANGE_PAR(MUL), NULL, NULL, NULL, NULL },												//< 乘法模块
	{ CALCU_SAMA(DIV), BC_PARA(DIV), CHANGE_PAR(DIV), NULL, NULL, NULL, NULL },												//< 除法模块
	{ CALCU_SAMA(SQUAROOT), BC_PARA(SQUAROOT), CHANGE_PAR(SQUAROOT), NULL, NULL, NULL, NULL },								//< 平方根模块
	{ CALCU_SAMA(ABS), BC_PARA(ABS), CHANGE_PAR(ABS), NULL, NULL, NULL, NULL },												//< 绝对值模块
	{ CALCU_SAMA(EXP), BC_PARA(EXP), CHANGE_PAR(EXP), NULL, NULL, NULL, NULL },												//< 指数模块
	{ CALCU_SAMA(POW), BC_PARA(POW), CHANGE_PAR(POW), NULL, NULL, NULL, NULL },												//< 幂函数模块
	{ CALCU_SAMA(LOG), BC_PARA(LOG), CHANGE_PAR(LOG), NULL, NULL, NULL, NULL },												//< 对数模块
	{ CALCU_SAMA(SIN), BC_PARA(SIN), CHANGE_PAR(SIN), NULL, NULL, NULL, NULL },												//< 三角函数模块
	{ CALCU_SAMA(ASIN), BC_PARA(ASIN), CHANGE_PAR(ASIN), NULL, NULL, NULL, NULL },											//< 反三角函数模块
	{ CALCU_SAMA(MATHS), BC_PARA(MATHS), CHANGE_PAR(MATHS), NULL, NULL, NULL, NULL },										//< 多项式模块
	{ CALCU_SAMA(ENTHALPY), NULL, NULL, NULL, NULL, NULL, NULL },															//< 焓值计算模块
	{ CALCU_SAMA(TS), BC_PARA(TS),CHANGE_PAR(TS), NULL, NULL,  NULL, NULL },			                                    //< 调整时间Ts指标计算模块  
	{ CALCU_SAMA(ATTRATE), BC_PARA(ATTRATE),CHANGE_PAR(ATTRATE), NULL, NULL,  NULL, NULL },                                 //< 衰减率指标计算模块

	/*输入输出模块枚举		IO_Model*/
	{ CALCU_SAMA(AI), BC_PARA(AI), CHANGE_PAR(AI), NULL, NULL, INIT_STAPAR(AI), NULL },						//< 模拟量输入模块
	{ CALCU_SAMA(AO), BC_PARA(AO), CHANGE_PAR(AO),NULL, NULL, INIT_STAPAR(AO), NULL },						//< 模拟量输出模块
	{ CALCU_SAMA(DI), BC_PARA(DI), CHANGE_PAR(DI), NULL, NULL, INIT_STAPAR(DI), NULL },						//< 开关量输入模块
	{ CALCU_SAMA(DO), BC_PARA(DO), CHANGE_PAR(DO), NULL, NULL, INIT_STAPAR(DO), NULL },						//< 开关量输出模块
	{ CALCU_SAMA(NETAI), BC_PARA(NETAI), CHANGE_PAR(NETAI), BAK_STA(NETAI), ANA_STA(NETAI), INIT_STAPAR(NETAI), NULL },		//< 站间通讯模拟量输入模块
	{ CALCU_SAMA(NETAO), NULL, NULL, NULL, NULL, NULL, NULL },																//< 站间通讯模拟量输出模块
	{ CALCU_SAMA(NETDI), BC_PARA(NETDI), CHANGE_PAR(NETDI), BAK_STA(NETDI), ANA_STA(NETDI), INIT_STAPAR(NETDI), NULL },		//< 站间通讯数字量输入模块
	{ CALCU_SAMA(NETDO), NULL, NULL, NULL, NULL, NULL, NULL },																//< 站间通讯数字量输出模块	
	{ CALCU_SAMA(AIGetFile), BC_PARA(AIGetFile), CHANGE_PAR(AIGetFile), NULL, NULL, NULL, NULL },							//< 数据采集模块
	{ CALCU_SAMA(FW), NULL, NULL, BAK_STA(FW), ANA_STA(FW), INIT_STAPAR(FW), NULL },						//< 文件写入数据模块
	{ CALCU_SAMA(FR), BC_PARA(FR), CHANGE_PAR(FR), BAK_STA(FR), ANA_STA(FR), INIT_STAPAR(FR), NULL },						        //< 文件读取数据模块


	/*逻辑运算模块枚举		Logic_Model*/
	{ CALCU_SAMA(AND), NULL, NULL, NULL, NULL, NULL, NULL },																//< 逻辑“与”模块
	{ CALCU_SAMA(OR), NULL, NULL, NULL, NULL, NULL, NULL },																	//< 逻辑“或”模块
	{ CALCU_SAMA(NOT), NULL, NULL, NULL, NULL, NULL, NULL },																//< 逻辑“非”模块
	{ CALCU_SAMA(XOR), NULL, NULL, NULL, NULL, NULL, NULL },																//< 逻辑“异或”模块
	{ CALCU_SAMA(SIGN), NULL, NULL, NULL, NULL, NULL, NULL },																//< 符号判断模块
	{ CALCU_SAMA(RSTRIG), NULL, NULL, NULL, NULL, NULL, NULL },																//< RS触发器模块
	{ CALCU_SAMA(DTRIG), BC_PARA(DTRIG), CHANGE_PAR(DTRIG), BAK_STA(DTRIG), ANA_STA(DTRIG), INIT_STAPAR(DTRIG), NULL },		//< D触发器模块
	{ CALCU_SAMA(COUNT), BC_PARA(COUNT), CHANGE_PAR(COUNT), BAK_STA(COUNT), ANA_STA(COUNT), INIT_STAPAR(COUNT), NULL },		//< 计数器模块
	{ CALCU_SAMA(COMPA), BC_PARA(COMPA), CHANGE_PAR(COMPA), NULL, NULL, NULL, NULL },										//< 比较器模块
	{ CALCU_SAMA(ALM), BC_PARA(ALM), CHANGE_PAR(ALM), NULL, NULL, NULL, NULL },												//< 偏差报警模块
	{ CALCU_SAMA(IN16OUT1), NULL, NULL, NULL, NULL, NULL, NULL },															//< 16-1模块
	{ CALCU_SAMA(IN1OUT16), NULL, NULL, NULL, NULL, NULL, NULL },															//< 1-16模块
	{ CALCU_SAMA(DTOA), NULL, NULL, NULL, NULL, NULL, NULL },																//< 数字量to模拟量模块
	{CALCU_SAMA(CONJUDE), NULL, NULL, NULL, NULL, NULL, NULL },                                                             //< 控制性能综合判断模块              
	{ CALCU_SAMA(IN1OUT32), NULL, NULL, NULL, NULL, NULL, NULL },															//< 1-32模块

	/*选择模块枚举			Choice_Model*/
	{ CALCU_SAMA(AISEL), BC_PARA(AISEL), CHANGE_PAR(AISEL), BAK_STA(AISEL), ANA_STA(AISEL), INIT_STAPAR(AISEL), NULL },		//< 模拟量输入选择模块
	{ CALCU_SAMA(AOSEL), BC_PARA(AOSEL), CHANGE_PAR(AOSEL), BAK_STA(AOSEL), ANA_STA(AOSEL), INIT_STAPAR(AOSEL), NULL },		//< 模拟量输出选择模块
	{ CALCU_SAMA(DISEL), NULL, NULL, NULL, NULL, NULL, NULL },																//< 数字量输入选择模块
	{ CALCU_SAMA(DOSEL), NULL, NULL, NULL, NULL, NULL, NULL },																//< 数字量输出选择模块
	{ CALCU_SAMA(MIDSEL), NULL, NULL, NULL, NULL, NULL, NULL },																//< 中间值选择模块
	{ CALCU_SAMA(MAXSEL), NULL, NULL, NULL, NULL, NULL, NULL },																//< 最大值选择模块
	{ CALCU_SAMA(MINSEL), NULL, NULL, NULL, NULL, NULL, NULL },																//< 最小值选择模块
	{ CALCU_SAMA(DG2OF3), NULL, NULL, NULL, NULL, NULL, NULL },																//< 数字信号3选2模块
	

	/*控制算法模块枚举		Control_Model*/
	{ CALCU_SAMA(PID), BC_PARA(PID), CHANGE_PAR(PID), BAK_STA(PID), ANA_STA(PID), INIT_STAPAR(PID), NULL },											//< PID控制模块
	{ CALCU_SAMA(AManSta), BC_PARA(AManSta), CHANGE_PAR(AManSta), BAK_STA(AManSta), ANA_STA(AManSta), INIT_STAPAR(AManSta), CMD_DEAL(AManSta) },	//< 模拟手动站模块
	{ CALCU_SAMA(DManSta), BC_PARA(DManSta), CHANGE_PAR(DManSta), BAK_STA(DManSta), ANA_STA(DManSta), INIT_STAPAR(DManSta), CMD_DEAL(DManSta) },	//< 数字手动站模块
	{ CALCU_SAMA(ASET), BC_PARA(ASET), CHANGE_PAR(ASET), BAK_STA(ASET), ANA_STA(ASET), INIT_STAPAR(ASET), CMD_DEAL(ASET) },							//< 模拟量给定值发生器模块
	{ CALCU_SAMA(DSET), BC_PARA(DSET), CHANGE_PAR(DSET), BAK_STA(DSET), ANA_STA(DSET), INIT_STAPAR(DSET), CMD_DEAL(DSET) },							//< 数字量给定值发生器模块
	{ CALCU_SAMA(LeadLag), NULL, NULL, BAK_STA(LeadLag), ANA_STA(LeadLag), INIT_STAPAR(LeadLag), NULL },					//< 超前滞后模块
	{ CALCU_SAMA(StepCont), BC_PARA(StepCont), CHANGE_PAR(StepCont), BAK_STA(StepCont), ANA_STA(StepCont), INIT_STAPAR(StepCont), NULL },			//< 步序控制模块
	{ CALCU_SAMA(In8Bala), BC_PARA(In8Bala), CHANGE_PAR(In8Bala), BAK_STA(In8Bala), ANA_STA(In8Bala), INIT_STAPAR(In8Bala), NULL },					//< 输入平衡模块(8IB)
	{ CALCU_SAMA(In2Bala), NULL, NULL, NULL, NULL, NULL, NULL },																					//< 输入平衡模块(2IB)
	{ CALCU_SAMA(Trans2), BC_PARA(Trans2), CHANGE_PAR(Trans2), BAK_STA(Trans2), ANA_STA(Trans2), INIT_STAPAR(Trans2), NULL },						//< 两变送器整合模块
	{ CALCU_SAMA(Trans3), BC_PARA(Trans3), CHANGE_PAR(Trans3), BAK_STA(Trans3), ANA_STA(Trans3), INIT_STAPAR(Trans3), NULL },						//< 三变送器整合模块
	{ CALCU_SAMA(DEVICE), BC_PARA(DEVICE), CHANGE_PAR(DEVICE), BAK_STA(DEVICE), ANA_STA(DEVICE), INIT_STAPAR(DEVICE), CMD_DEAL(DEVICE) },			//< 设备驱动模块
	{ CALCU_SAMA(StimuSigCon), BC_PARA(StimuSigCon), CHANGE_PAR(StimuSigCon), BAK_STA(StimuSigCon), ANA_STA(StimuSigCon), INIT_STAPAR(StimuSigCon), NULL },			//< 激励信号启停模块
	{ CALCU_SAMA(DMC), BC_PARA(DMC), CHANGE_PAR(DMC), BAK_STA(DMC), ANA_STA(DMC), INIT_STAPAR(DMC), NULL },											//< DMC模块
	{ CALCU_SAMA(DstrbOn), BC_PARA(DstrbOn), CHANGE_PAR(DstrbOn), BAK_STA(DstrbOn), ANA_STA(DstrbOn), INIT_STAPAR(DstrbOn), NULL },                 //< 扰动启动模块
	{ CALCU_SAMA(FFDMC), BC_PARA(FFDMC), CHANGE_PAR(FFDMC), BAK_STA(FFDMC), ANA_STA(FFDMC), INIT_STAPAR(FFDMC), NULL },								////< FFDMC模块

	/*时间算法模块枚举		Time_Model*/
	{ CALCU_SAMA(TIMER), BC_PARA(TIMER), CHANGE_PAR(TIMER), BAK_STA(TIMER), ANA_STA(TIMER), INIT_STAPAR(TIMER), NULL },		//< 定时器模块
	{ CALCU_SAMA(CYCTIMER), BC_PARA(CYCTIMER), CHANGE_PAR(CYCTIMER), NULL, NULL, NULL, NULL },								//< 周期定时器模块
	{ CALCU_SAMA(TOTAL), BC_PARA(TOTAL), CHANGE_PAR(TOTAL), BAK_STA(TOTAL), ANA_STA(TOTAL), INIT_STAPAR(TOTAL), NULL },		//< 积算器模块
	{ CALCU_SAMA(TIMEGET), NULL, NULL, NULL, NULL, NULL, NULL },															//< 时间获取模块
	{ CALCU_SAMA(STACK), BC_PARA(STACK), CHANGE_PAR(STACK), BAK_STA(STACK), ANA_STA(STACK), INIT_STAPAR(STACK), NULL },		//< 数据堆栈模块
	{ CALCU_SAMA(PUL), BC_PARA(PUL), CHANGE_PAR(PUL), BAK_STA(PUL), ANA_STA(PUL), INIT_STAPAR(PUL), NULL },		                                 //< 脉冲模块
	{ CALCU_SAMA(DELAYON), BC_PARA(DELAYON), CHANGE_PAR(DELAYON), BAK_STA(DELAYON), ANA_STA(DELAYON), INIT_STAPAR(DELAYON), NULL },		         //< 延时开模块
	{ CALCU_SAMA(DELAYOFF), BC_PARA(DELAYOFF), CHANGE_PAR(DELAYOFF), BAK_STA(DELAYOFF), ANA_STA(DELAYOFF), INIT_STAPAR(DELAYOFF), NULL },		 //< 延时关模块
	
	/*线性算法模块枚举		Line_Model*/
	{ CALCU_SAMA(CONST), BC_PARA(CONST), CHANGE_PAR(CONST), NULL, NULL, NULL, NULL },										//< 常系数模块
	{ CALCU_SAMA(DELAY), BC_PARA(DELAY), CHANGE_PAR(DELAY), BAK_STA(DELAY), ANA_STA(DELAY), INIT_STAPAR(DELAY), NULL },		//< 纯迟延模块
	{ CALCU_SAMA(INTEG), BC_PARA(INTEG), CHANGE_PAR(INTEG), BAK_STA(INTEG), ANA_STA(INTEG), INIT_STAPAR(INTEG), NULL },		//< 积分信号模块
	{ CALCU_SAMA(DIFFE), BC_PARA(DIFFE), CHANGE_PAR(DIFFE), BAK_STA(DIFFE), ANA_STA(DIFFE), INIT_STAPAR(DIFFE), NULL },		//< 微分信号模块
	{ CALCU_SAMA(CTF1), BC_PARA(CTF1), CHANGE_PAR(CTF1), BAK_STA(CTF1), ANA_STA(CTF1), INIT_STAPAR(CTF1), NULL },			//< 连续传递函数1模块
	{ CALCU_SAMA(CTF2), BC_PARA(CTF2), CHANGE_PAR(CTF2), BAK_STA(CTF2), ANA_STA(CTF2), INIT_STAPAR(CTF2), NULL },			//< 连续传递函数2模块
	{ CALCU_SAMA(DTF), BC_PARA(DTF), CHANGE_PAR(DTF), BAK_STA(DTF), ANA_STA(DTF), INIT_STAPAR(DTF), NULL },					//< 离散传递函数模块
	{ CALCU_SAMA(DISUM), BC_PARA(DISUM), CHANGE_PAR(DISUM), BAK_STA(DISUM), ANA_STA(DISUM), INIT_STAPAR(DISUM), NULL },		//< 数字信号加法器功能块
	
	/*非线性算法模块枚举	NonLine_Model*/
	{ CALCU_SAMA(RANGE), NULL, NULL, NULL, NULL, NULL, NULL },																				//< 限幅模块													                                   
	{ CALCU_SAMA(RANGEALM), BC_PARA(RANGEALM), CHANGE_PAR(RANGEALM), BAK_STA(RANGEALM), ANA_STA(RANGEALM), INIT_STAPAR(RANGEALM), NULL },	//< 幅值报警模块				                                  
	{ CALCU_SAMA(RATE), NULL, NULL,BAK_STA(RATE), ANA_STA(RATE),  INIT_STAPAR(RATE), NULL },												//< 速率限制模块
	{ CALCU_SAMA(RATEALM), BC_PARA(RATEALM), CHANGE_PAR(RATEALM), BAK_STA(RATEALM), ANA_STA(RATEALM), INIT_STAPAR(RATEALM), NULL },			//< 速率报警模块                                         
	{ CALCU_SAMA(DEAD), BC_PARA(DEAD),CHANGE_PAR(DEAD), NULL, NULL, NULL, NULL },															//< 死区模块                           
	{ CALCU_SAMA(SWITCH), BC_PARA(SWITCH), CHANGE_PAR(SWITCH),NULL, NULL, NULL, NULL },														//< 开关模块                                    
	{ CALCU_SAMA(GEARBL), BC_PARA(GEARBL),CHANGE_PAR(GEARBL), BAK_STA(GEARBL), ANA_STA(GEARBL),  INIT_STAPAR(GEARBL), NULL },				//< 齿轮间隙模块                
	{ CALCU_SAMA(HYLOOP), BC_PARA(HYLOOP),CHANGE_PAR(HYLOOP), BAK_STA(HYLOOP), ANA_STA(HYLOOP), INIT_STAPAR(HYLOOP), NULL },				//< 滞环开关模块                                         
	{ CALCU_SAMA(MAGAMP), BC_PARA(MAGAMP), CHANGE_PAR(MAGAMP),BAK_STA(MAGAMP), ANA_STA(MAGAMP), INIT_STAPAR(MAGAMP), NULL },				//< 磁放模块                                            
	{ CALCU_SAMA(MLINE), BC_PARA(MLINE),CHANGE_PAR(MLINE), NULL, NULL, NULL, NULL },														//< 分段线性模块
	
	/*设备驱动模块枚举		DeviceDriver_Model*/
	
};


/*SAMA模块链表数组（严格按照.h文件中SAMA模块类型枚举顺序）*/
List_Tab_t Model_List[TYP_MAX_MODEL] =
{
	/*自定义算法模块枚举	UserDefined_Model*/
	{ ELE_PNT(USERDEF), TYPE(USERDEF), ELE_LEN(USERDEF), 0, MLIST_PAR(USERDEF), MLIST_FUNC(USERDEF) },

	/*信号源模块枚举		SignalSource_Model*/
	{ ELE_PNT(STEP), TYPE(STEP), ELE_LEN(STEP), 0, MLIST_PAR(STEP), MLIST_FUNC(STEP) },								//< 阶跃信号模块
	{ ELE_PNT(RAMP), TYPE(RAMP), ELE_LEN(RAMP), 0, MLIST_PAR(RAMP), MLIST_FUNC(RAMP) },								//< 斜坡信号模块
	{ ELE_PNT(SINSOURCE), TYPE(SINSOURCE), ELE_LEN(SINSOURCE), 0, MLIST_PAR(SINSOURCE), MLIST_FUNC(SINSOURCE) },	//< 正弦信号模块
	{ ELE_PNT(SQUA), TYPE(SQUA), ELE_LEN(SQUA), 0, MLIST_PAR(SQUA), MLIST_FUNC(SQUA) },								//< 方波信号模块
	{ ELE_PNT(SAW), TYPE(SAW), ELE_LEN(SAW), 0, MLIST_PAR(SAW), MLIST_FUNC(SAW) },									//< 锯齿波信号模块
	{ ELE_PNT(BROK), TYPE(BROK), ELE_LEN(BROK), 0, MLIST_PAR(BROK), MLIST_FUNC(BROK) },								//< 折线信号模块  
	{ ELE_PNT(MSQUA), TYPE(MSQUA), ELE_LEN(MSQUA), 0, MLIST_PAR(MSQUA), MLIST_FUNC(MSQUA) },						//< 多段方波信号模块
	{ ELE_PNT(RAND), TYPE(RAND), ELE_LEN(RAND), 0, MLIST_PAR(RAND), MLIST_FUNC(RAND) },								//< 随机信号模块	
	{ ELE_PNT(PRBS), TYPE(PRBS), ELE_LEN(PRBS), 0, MLIST_PAR(PRBS), MLIST_FUNC(PRBS) }, 							//< 伪随机序列信号模块
	{ ELE_PNT(FIXPULSE), TYPE(FIXPULSE), ELE_LEN(FIXPULSE), 0, MLIST_PAR(FIXPULSE), MLIST_FUNC(FIXPULSE) },			//< 固定脉冲信号模块
	{ ELE_PNT(SETSTEP), TYPE(SETSTEP), ELE_LEN(SETSTEP), 0, MLIST_PAR(SETSTEP), MLIST_FUNC(SETSTEP) },			    //< 设定值阶跃扰动模块

	/*数学运算模块枚举		Math_Model*/
	{ ELE_PNT(ADD), TYPE(ADD), ELE_LEN(ADD), 0, MLIST_PAR(ADD), MLIST_FUNC(ADD)},							//< 加法模块
	{ ELE_PNT(SUB), TYPE(SUB), ELE_LEN(SUB), 0, MLIST_PAR(SUB), MLIST_FUNC(SUB)},							//< 减法模块
	{ ELE_PNT(MUL), TYPE(MUL), ELE_LEN(MUL), 0, MLIST_PAR(MUL), MLIST_FUNC(MUL)},							//< 乘法模块
	{ ELE_PNT(DIV), TYPE(DIV), ELE_LEN(DIV), 0, MLIST_PAR(DIV), MLIST_FUNC(DIV)},							//< 除法模块
	{ ELE_PNT(SQUAROOT), TYPE(SQUAROOT), ELE_LEN(SQUAROOT), 0, MLIST_PAR(SQUAROOT), MLIST_FUNC(SQUAROOT)},	//< 平方根模块
	{ ELE_PNT(ABS), TYPE(ABS), ELE_LEN(ABS), 0, MLIST_PAR(ABS), MLIST_FUNC(ABS)},							//< 绝对值模块
	{ ELE_PNT(EXP), TYPE(EXP), ELE_LEN(EXP), 0, MLIST_PAR(EXP), MLIST_FUNC(EXP)},							//< 指数模块
	{ ELE_PNT(POW), TYPE(POW), ELE_LEN(POW), 0, MLIST_PAR(POW), MLIST_FUNC(POW)},							//< 幂函数模块
	{ ELE_PNT(LOG), TYPE(LOG), ELE_LEN(LOG), 0, MLIST_PAR(LOG), MLIST_FUNC(LOG)},							//< 对数模块
	{ ELE_PNT(SIN), TYPE(SIN), ELE_LEN(SIN), 0, MLIST_PAR(SIN), MLIST_FUNC(SIN)},							//< 三角函数模块
	{ ELE_PNT(ASIN), TYPE(ASIN), ELE_LEN(ASIN), 0, MLIST_PAR(ASIN), MLIST_FUNC(ASIN)},						//< 反三角函数模块
	{ ELE_PNT(MATHS), TYPE(MATHS), ELE_LEN(MATHS), 0, MLIST_PAR(MATHS), MLIST_FUNC(MATHS)},					//< 多项式模块
	{ ELE_PNT(ENTHALPY), TYPE(ENTHALPY), ELE_LEN(ENTHALPY), 0, MLIST_PAR(ENTHALPY), MLIST_FUNC(ENTHALPY)},	//< 焓值计算模块
	{ ELE_PNT(TS), TYPE(TS), ELE_LEN(TS), 0, MLIST_PAR(TS), MLIST_FUNC(TS)},	                            //< 调整时间Ts指标计算模块 
	{ ELE_PNT(ATTRATE), TYPE(ATTRATE), ELE_LEN(ATTRATE), 0, MLIST_PAR(ATTRATE), MLIST_FUNC(ATTRATE)},	    //< 衰减率指标计算模块 

	/*输入输出模块枚举		IO_Model*/
	{ ELE_PNT(AI), TYPE(AI), ELE_LEN(AI), 0, MLIST_PAR(AI), MLIST_FUNC(AI)},								//< 模拟量输入模块
	{ ELE_PNT(AO), TYPE(AO), ELE_LEN(AO), 0, MLIST_PAR(AO), MLIST_FUNC(AO)},								//< 模拟量输出模块
	{ ELE_PNT(DI), TYPE(DI), ELE_LEN(DI), 0, MLIST_PAR(DI), MLIST_FUNC(DI)},								//< 开关量输入模块
	{ ELE_PNT(DO), TYPE(DO), ELE_LEN(DO), 0, MLIST_PAR(DO), MLIST_FUNC(DO)},								//< 开关量输出模块
	{ ELE_PNT(NETAI), TYPE(NETAI), ELE_LEN(NETAI), 0, MLIST_PAR(NETAI), MLIST_FUNC(NETAI)},					//< 站间通讯模拟量输入模块
	{ ELE_PNT(NETAO), TYPE(NETAO), ELE_LEN(NETAO), 0, MLIST_PAR(NETAO), MLIST_FUNC(NETAO)},					//< 站间通讯模拟量输出模块
	{ ELE_PNT(NETDI), TYPE(NETDI), ELE_LEN(NETDI), 0, MLIST_PAR(NETDI), MLIST_FUNC(NETDI)},					//< 站间通讯数字量输入模块
	{ ELE_PNT(NETDO), TYPE(NETDO), ELE_LEN(NETDO), 0, MLIST_PAR(NETDO), MLIST_FUNC(NETDO)},					//< 站间通讯数字量输出模块	
	{ ELE_PNT(AIGetFile), TYPE(AIGetFile), ELE_LEN(AIGetFile), 0, MLIST_PAR(AIGetFile), MLIST_FUNC(AIGetFile)},	//< 数据采集模块
	{ ELE_PNT(FW), TYPE(FW), ELE_LEN(FW), 0, MLIST_PAR(FW), MLIST_FUNC(FW)},								//< 文件写入数据模块
	{ ELE_PNT(FR), TYPE(FR), ELE_LEN(FR), 0, MLIST_PAR(FR), MLIST_FUNC(FR)},								//< 文件读取数据模块

	/*逻辑运算模块枚举		Logic_Model*/
	{ ELE_PNT(AND), TYPE(AND), ELE_LEN(AND), 0, MLIST_PAR(AND), MLIST_FUNC(AND)},							//< 逻辑“与”模块
	{ ELE_PNT(OR), TYPE(OR), ELE_LEN(OR), 0, MLIST_PAR(OR), MLIST_FUNC(OR)},								//< 逻辑“或”模块
	{ ELE_PNT(NOT), TYPE(NOT), ELE_LEN(NOT), 0, MLIST_PAR(NOT), MLIST_FUNC(NOT)},							//< 逻辑“非”模块
	{ ELE_PNT(XOR), TYPE(XOR), ELE_LEN(XOR), 0, MLIST_PAR(XOR), MLIST_FUNC(XOR)},							//< 逻辑“异或”模块
	{ ELE_PNT(SIGN), TYPE(SIGN), ELE_LEN(SIGN), 0, MLIST_PAR(SIGN), MLIST_FUNC(SIGN)},						//< 符号判断模块
	{ ELE_PNT(RSTRIG), TYPE(RSTRIG), ELE_LEN(RSTRIG), 0, MLIST_PAR(RSTRIG), MLIST_FUNC(RSTRIG)},			//< RS触发器模块
	{ ELE_PNT(DTRIG), TYPE(DTRIG), ELE_LEN(DTRIG), 0, MLIST_PAR(DTRIG), MLIST_FUNC(DTRIG)},					//< D触发器模块
	{ ELE_PNT(COUNT), TYPE(COUNT), ELE_LEN(COUNT), 0, MLIST_PAR(COUNT), MLIST_FUNC(COUNT)},					//< 计数器模块
	{ ELE_PNT(COMPA), TYPE(COMPA), ELE_LEN(COMPA), 0, MLIST_PAR(COMPA), MLIST_FUNC(COMPA)},					//< 比较器模块
	{ ELE_PNT(ALM), TYPE(ALM), ELE_LEN(ALM), 0, MLIST_PAR(ALM), MLIST_FUNC(ALM)},							//< 偏差报警模块
	{ ELE_PNT(IN16OUT1), TYPE(IN16OUT1), ELE_LEN(IN16OUT1), 0, MLIST_PAR(IN16OUT1), MLIST_FUNC(IN16OUT1)},	//< 16-1模块
	{ ELE_PNT(IN1OUT16), TYPE(IN1OUT16), ELE_LEN(IN1OUT16), 0, MLIST_PAR(IN1OUT16), MLIST_FUNC(IN1OUT16)},	//< 1-16模块
	{ ELE_PNT(DTOA), TYPE(DTOA), ELE_LEN(DTOA), 0, MLIST_PAR(DTOA), MLIST_FUNC(DTOA)},						//< 数字量to模拟量模块
	{ ELE_PNT(CONJUDE), TYPE(CONJUDE),ELE_LEN(CONJUDE),0 ,MLIST_PAR(CONJUDE),MLIST_FUNC(CONJUDE)},          //< 控制性能综合判断模块
	{ ELE_PNT(IN1OUT32), TYPE(IN1OUT32), ELE_LEN(IN1OUT32), 0, MLIST_PAR(IN1OUT32), MLIST_FUNC(IN1OUT32)},	//< 1-32模块

	/*选择模块枚举			Choice_Model*/
	{ ELE_PNT(AISEL), TYPE(AISEL), ELE_LEN(AISEL), 0, MLIST_PAR(AISEL), MLIST_FUNC(AISEL)},					//< 模拟量输入选择模块
	{ ELE_PNT(AOSEL), TYPE(AOSEL), ELE_LEN(AOSEL), 0, MLIST_PAR(AOSEL), MLIST_FUNC(AOSEL)},					//< 模拟量输出选择模块
	{ ELE_PNT(DISEL), TYPE(DISEL), ELE_LEN(DISEL), 0, MLIST_PAR(DISEL), MLIST_FUNC(DISEL)},					//< 数字量输入选择模块
	{ ELE_PNT(DOSEL), TYPE(DOSEL), ELE_LEN(DOSEL), 0, MLIST_PAR(DOSEL), MLIST_FUNC(DOSEL)},					//< 数字量输出选择模块
	{ ELE_PNT(MIDSEL), TYPE(MIDSEL), ELE_LEN(MIDSEL), 0, MLIST_PAR(MIDSEL), MLIST_FUNC(MIDSEL)},			//< 中间值选择模块
	{ ELE_PNT(MAXSEL), TYPE(MAXSEL), ELE_LEN(MAXSEL), 0, MLIST_PAR(MAXSEL), MLIST_FUNC(MAXSEL)},			//< 最大值选择模块
	{ ELE_PNT(MINSEL), TYPE(MINSEL), ELE_LEN(MINSEL), 0, MLIST_PAR(MINSEL), MLIST_FUNC(MINSEL)},			//< 最小值选择模块
	{ ELE_PNT(DG2OF3), TYPE(DG2OF3), ELE_LEN(DG2OF3), 0, MLIST_PAR(DG2OF3), MLIST_FUNC(DG2OF3)},			//< 数字信号3选2模块
	

	/*控制算法模块枚举		Control_Model*/
	{ ELE_PNT(PID), TYPE(PID), ELE_LEN(PID), 0, MLIST_PAR(PID), MLIST_FUNC(PID)},							//< PID控制模块
	{ ELE_PNT(AManSta), TYPE(AManSta), ELE_LEN(AManSta), 0, MLIST_PAR(AManSta), MLIST_FUNC(AManSta)},		//< 模拟手动站模块
	{ ELE_PNT(DManSta), TYPE(DManSta), ELE_LEN(DManSta), 0, MLIST_PAR(DManSta), MLIST_FUNC(DManSta)},		//< 数字手动站模块
	{ ELE_PNT(ASET), TYPE(ASET), ELE_LEN(ASET), 0, MLIST_PAR(ASET), MLIST_FUNC(ASET)},						//< 模拟量给定值发生器模块
	{ ELE_PNT(DSET), TYPE(DSET), ELE_LEN(DSET), 0, MLIST_PAR(DSET), MLIST_FUNC(DSET)},						//< 数字量给定值发生器模块
	{ ELE_PNT(LeadLag), TYPE(LeadLag), ELE_LEN(LeadLag), 0, MLIST_PAR(LeadLag), MLIST_FUNC(LeadLag)},		//< 超前滞后模块
	{ ELE_PNT(StepCont), TYPE(StepCont), ELE_LEN(StepCont), 0, MLIST_PAR(StepCont), MLIST_FUNC(StepCont)},	//< 步序控制模块
	{ ELE_PNT(In8Bala), TYPE(In8Bala), ELE_LEN(In8Bala), 0, MLIST_PAR(In8Bala), MLIST_FUNC(In8Bala)},		//< 输入平衡模块(8IB)
	{ ELE_PNT(In2Bala), TYPE(In2Bala), ELE_LEN(In2Bala), 0, MLIST_PAR(In2Bala), MLIST_FUNC(In2Bala)},		//< 输入平衡模块(2IB)
	{ ELE_PNT(Trans2), TYPE(Trans2), ELE_LEN(Trans2), 0, MLIST_PAR(Trans2), MLIST_FUNC(Trans2)},			//< 两变送器整合模块
	{ ELE_PNT(Trans3), TYPE(Trans3), ELE_LEN(Trans3), 0, MLIST_PAR(Trans3), MLIST_FUNC(Trans3)},			//< 三变送器整合模块
	{ ELE_PNT(DEVICE), TYPE(DEVICE), ELE_LEN(DEVICE), 0, MLIST_PAR(DEVICE), MLIST_FUNC(DEVICE)},			//< 设备驱动模块
	{ ELE_PNT(StimuSigCon), TYPE(StimuSigCon), ELE_LEN(StimuSigCon), 0, MLIST_PAR(StimuSigCon), MLIST_FUNC(StimuSigCon)},			//< 设备驱动模块
	{ ELE_PNT(DMC), TYPE(DMC), ELE_LEN(DMC), 0, MLIST_PAR(DMC), MLIST_FUNC(DMC) },							//< DMC模块
	{ ELE_PNT(DstrbOn), TYPE(DstrbOn), ELE_LEN(DstrbOn), 0, MLIST_PAR(DstrbOn), MLIST_FUNC(DstrbOn) },  //< 扰动启动模块
	{ ELE_PNT(FFDMC), TYPE(FFDMC), ELE_LEN(FFDMC), 0, MLIST_PAR(FFDMC), MLIST_FUNC(FFDMC) },				////< FFDMC模块

	/*时间算法模块枚举		Time_Model*/
	{ ELE_PNT(TIMER), TYPE(TIMER), ELE_LEN(TIMER), 0, MLIST_PAR(TIMER), MLIST_FUNC(TIMER)},					//< 定时器模块
	{ ELE_PNT(CYCTIMER), TYPE(CYCTIMER), ELE_LEN(CYCTIMER), 0, MLIST_PAR(CYCTIMER), MLIST_FUNC(CYCTIMER)},	//< 周期定时器模块
	{ ELE_PNT(TOTAL), TYPE(TOTAL), ELE_LEN(TOTAL), 0, MLIST_PAR(TOTAL), MLIST_FUNC(TOTAL)},					//< 积算器模块
	{ ELE_PNT(TIMEGET), TYPE(TIMEGET), ELE_LEN(TIMEGET), 0, MLIST_PAR(TIMEGET), MLIST_FUNC(TIMEGET)},		//< 时间获取模块
	{ ELE_PNT(STACK), TYPE(STACK), ELE_LEN(STACK), 0, MLIST_PAR(STACK), MLIST_FUNC(STACK)},					//< 数据堆栈模块
	{ ELE_PNT(PUL), TYPE(PUL), ELE_LEN(PUL), 0, MLIST_PAR(PUL), MLIST_FUNC(PUL)},					        //< 脉冲模块
	{ ELE_PNT(DELAYON), TYPE(DELAYON), ELE_LEN(DELAYON), 0, MLIST_PAR(DELAYON), MLIST_FUNC(DELAYON)},		//< 延时开模块
	{ ELE_PNT(DELAYOFF), TYPE(DELAYOFF), ELE_LEN(DELAYOFF), 0, MLIST_PAR(DELAYOFF), MLIST_FUNC(DELAYOFF)},	//< 延时关模块

	/*线性算法模块枚举		Line_Model*/
	{ ELE_PNT(CONST), TYPE(CONST), ELE_LEN(CONST), 0, MLIST_PAR(CONST), MLIST_FUNC(CONST)},					//< 常系数模块
	{ ELE_PNT(DELAY), TYPE(DELAY), ELE_LEN(DELAY), 0, MLIST_PAR(DELAY), MLIST_FUNC(DELAY)},					//< 纯迟延模块
	{ ELE_PNT(INTEG), TYPE(INTEG), ELE_LEN(INTEG), 0, MLIST_PAR(INTEG), MLIST_FUNC(INTEG)},					//< 积分模块
	{ ELE_PNT(DIFFE), TYPE(DIFFE), ELE_LEN(DIFFE), 0, MLIST_PAR(DIFFE), MLIST_FUNC(DIFFE)},					//< 微分模块
	{ ELE_PNT(CTF1), TYPE(CTF1), ELE_LEN(CTF1), 0, MLIST_PAR(CTF1), MLIST_FUNC(CTF1)},						//< 连续传递函数1模块
	{ ELE_PNT(CTF2), TYPE(CTF2), ELE_LEN(CTF2), 0, MLIST_PAR(CTF2), MLIST_FUNC(CTF2)},						//< 连续传递函数2模块
	{ ELE_PNT(DTF), TYPE(DTF), ELE_LEN(DTF), 0, MLIST_PAR(DTF), MLIST_FUNC(DTF)},							//< 离散传递函数模块
	{ ELE_PNT(DISUM), TYPE(DISUM), ELE_LEN(DISUM), 0, MLIST_PAR(DISUM), MLIST_FUNC(DISUM)},					//< 数字信号加法器模块
	

	/*非线性算法模块枚举	NonLine_Model*/
	{ ELE_PNT(RANGE), TYPE(RANGE), ELE_LEN(RANGE), 0, MLIST_PAR(RANGE), MLIST_FUNC(RANGE) },				//< 限幅模块					
	{ ELE_PNT(RANGEALM), TYPE(RANGEALM), ELE_LEN(RANGEALM), 0, MLIST_PAR(RANGEALM), MLIST_FUNC(RANGEALM) },	//< 幅值报警模块		                
	{ ELE_PNT(RATE), TYPE(RATE), ELE_LEN(RATE), 0, MLIST_PAR(RATE), MLIST_FUNC(RATE) },						//< 速率限制模块
	{ ELE_PNT(RATEALM), TYPE(RATEALM), ELE_LEN(RATEALM), 0, MLIST_PAR(RATEALM), MLIST_FUNC(RATEALM) },		//< 速率报警模块		               
	{ ELE_PNT(DEAD), TYPE(DEAD), ELE_LEN(DEAD), 0, MLIST_PAR(DEAD), MLIST_FUNC(DEAD) },						//< 死区模块       
	{ ELE_PNT(SWITCH), TYPE(SWITCH), ELE_LEN(SWITCH), 0, MLIST_PAR(SWITCH), MLIST_FUNC(SWITCH) },			//< 开关模块              
	{ ELE_PNT(GEARBL), TYPE(GEARBL), ELE_LEN(GEARBL), 0, MLIST_PAR(GEARBL), MLIST_FUNC(GEARBL) },			//< 齿轮间隙模块      
	{ ELE_PNT(HYLOOP), TYPE(HYLOOP), ELE_LEN(HYLOOP), 0, MLIST_PAR(HYLOOP), MLIST_FUNC(HYLOOP) },			//< 滞环开关模块               
	{ ELE_PNT(MAGAMP), TYPE(MAGAMP), ELE_LEN(MAGAMP), 0, MLIST_PAR(MAGAMP), MLIST_FUNC(MAGAMP) },			//< 磁放模块        
	{ ELE_PNT(MLINE), TYPE(MLINE), ELE_LEN(MLINE), 0, MLIST_PAR(MLINE), MLIST_FUNC(MLINE) },				//< 分段线性模块  
	
	/*设备驱动模块枚举		DeviceDriver_Model*/
	
};


//************************************
// Method:    	FreeSAMAIO					SAMA模块IO内存释放函数
// Programmer:  lww
// Time:		2018/11/13
// Returns:   	void
// Parameter: 	Model_Base_t * base			模块参变量结构体首地址
//************************************
void FreeSAMAIO(Model_Base_t* base)
{
	//< 释放输入引脚相关内存
	FREE_Pt(base->In.AI);
	FREE_Pt(base->In.DI);

	FREE_Pt(base->In.AI_Pin_ID);
	FREE_Pt(base->In.AI_Pin_Type);
	FREE_Pt(base->In.AI_Pin_Num);

	FREE_Pt(base->In.DI_Pin_ID);
	FREE_Pt(base->In.DI_Pin_Type);
	FREE_Pt(base->In.DI_Pin_Num);

	FREE_Pt(base->In.AI_Pin_QualityInfo);
	FREE_Pt(base->In.DI_Pin_QualityInfo);

	//< 释放输出引脚相关内存
	FREE_Pt(base->Out.AO);
	FREE_Pt(base->Out.Last_AO);
	FREE_Pt(base->Out.DO);
	FREE_Pt(base->Out.Last_DO);

	FREE_Pt(base->Out.AO_PinSta);
	FREE_Pt(base->Out.DO_PinSta);
}


//************************************
// Method:    	AddModel					增加SAMA模块函数
// Programmer:  lww
// Time:		2018/11/13
// Returns:   	List_Info_e					LIST_MEMFAIL——内存开辟失败
//											LIST_IDEXIT——所需开辟的ID号的模块已存在
//											LIST_OK——模块增加成功
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						新增模块的ID号
// Parameter: 	IO_PinNum_t IONum			新增模块的IO引脚数量结构体
//************************************
List_Info_e AddModel(List_Tab_t* arg, unsigned int ID, SAMA_Model_IO_Num_t* IO_PinNum)
{
	List_Info_e info;
	info = AddElement(arg, ID);					//< 增加元素
	if (info == LIST_IDEXIT)					//< ID号已经存在
	{
		printf("ID = %d has been exsit\r\n", ID);
		return LIST_IDEXIT;
	}
	else if (info == LIST_MEMFAIL)				//< 操作内存失败
	{
		printf("Calloc memrory failed in ID = %d\r\n", ID);
		return LIST_MEMFAIL;
	}

	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);

	if (base != NULL)
	{
		if (IO_PinNum != NULL)
		{
			//< 初始化模块输入输出引脚数量
			base->IO_Num = IO_PinNum[0];

			//< 初始化模块输入引脚相关参数
			MODEL_IO_MEMFAIL_DEAL(base->In.AI = (float**)calloc(IO_PinNum->AI_Num, sizeof(float*)));
			MODEL_IO_MEMFAIL_DEAL(base->In.DI = (bool**)calloc(IO_PinNum->DI_Num, sizeof(bool*)));

			MODEL_IO_MEMFAIL_DEAL(base->In.AI_Pin_ID = (int*)calloc(IO_PinNum->AI_Num, sizeof(int)));
			MODEL_IO_MEMFAIL_DEAL(base->In.AI_Pin_Type = (int*)calloc(IO_PinNum->AI_Num, sizeof(int)));
			MODEL_IO_MEMFAIL_DEAL(base->In.AI_Pin_Num = (int*)calloc(IO_PinNum->AI_Num, sizeof(int)));

			MODEL_IO_MEMFAIL_DEAL(base->In.DI_Pin_ID = (int*)calloc(IO_PinNum->DI_Num, sizeof(int)));
			MODEL_IO_MEMFAIL_DEAL(base->In.DI_Pin_Type = (int*)calloc(IO_PinNum->DI_Num, sizeof(int)));
			MODEL_IO_MEMFAIL_DEAL(base->In.DI_Pin_Num = (int*)calloc(IO_PinNum->DI_Num, sizeof(int)));

			MODEL_IO_MEMFAIL_DEAL(base->In.AI_Pin_QualityInfo = (bool**)calloc(IO_PinNum->AI_Num, sizeof(bool*)));
			MODEL_IO_MEMFAIL_DEAL(base->In.DI_Pin_QualityInfo = (bool**)calloc(IO_PinNum->DI_Num, sizeof(bool*)));

			//< 初始化模块输出引脚相关参数
			MODEL_IO_MEMFAIL_DEAL(base->Out.AO = (float*)calloc(IO_PinNum->AO_Num, sizeof(float)));
			MODEL_IO_MEMFAIL_DEAL(base->Out.DO = (bool*)calloc(IO_PinNum->DO_Num, sizeof(bool)));
			MODEL_IO_MEMFAIL_DEAL(base->Out.Last_AO = (float*)calloc(IO_PinNum->AO_Num, sizeof(float)));
			MODEL_IO_MEMFAIL_DEAL(base->Out.Last_DO = (bool*)calloc(IO_PinNum->DO_Num, sizeof(bool)));
			MODEL_IO_MEMFAIL_DEAL(base->Out.Attend_Sta = (BAK_Attend_Sta_t*)calloc(IO_PinNum->AO_Num, sizeof(BAK_Attend_Sta_t)));

			MODEL_IO_MEMFAIL_DEAL(base->Out.AO_PinSta = (IOSta_e *)calloc(IO_PinNum->AO_Num, sizeof(IOSta_e)));			//< duan0518 calloc初始化内存中存储值0，故默认下，引脚输出状态均为正常
			MODEL_IO_MEMFAIL_DEAL(base->Out.DO_PinSta = (IOSta_e *)calloc(IO_PinNum->DO_Num, sizeof(IOSta_e)));
		}
		return LIST_OK;
	}
	return LIST_IDNON;

}


//************************************
// Method:    	DelModel					删除SAMA模块函数
// Programmer:  lww
// Time:		2018/11/14
// Returns:   	List_Info_e					LIST_IDNON——所需删除的ID号的模块不存在
//											LIST_OK——模块删除成功
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						被删除模块的ID号
//************************************
List_Info_e DelModel(List_Tab_t* arg, unsigned int ID)
{
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);

	if (base != NULL)
	{
		FreeSAMAIO(base);
		if (LIST_OK == DelElement(arg, ID))
			return LIST_OK;
	}
	return LIST_IDNON;
}


//************************************
// Method:    	BCSAMA						广播SAMA函数
// Programmer:  lww
// Time:		2018/11/16
// Returns:   	int							成功：返回打包字节个数；失败：返回0
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						广播SAMA的模块的ID号
// Parameter: 	void ** Data				广播SAMA的数据包的指针的指针
// Parameter: 	short * BCNum				广播SAMA的模块数量的计数变量的指针
//************************************
int BCSAMA(List_Tab_t* arg, unsigned int ID, void** Data, short *BCNum)
{
#define MEMWRITE1(name)	MEMWRITE(name, Data[0])

	int _iLen = 0;
	short tmp_short;
	float tmp_float;

	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t *)(arg->ppData[0]), ID);

	if (base != NULL)
	{
		if (SAMA_PageBCFlag[base->PageNum - 1])
		{
			//< 广播公有参数
			MEMWRITE1(base->List_Base.ID);
			//MEMWRITE1(base->Out.A_QualityInfo);
			//MEMWRITE1(base->Out.D_QualityInfo);

			tmp_short = base->IO_Num.AO_Num;
			MEMWRITE1(tmp_short);
			for (int i = 0; i < base->IO_Num.AO_Num; i++)
			{
				tmp_short = base->Out.AO_PinSta[i];
				MEMWRITE1(tmp_short);
				tmp_float = base->Out.AO[i];
				MEMWRITE1(tmp_float);
			}

			tmp_short = base->IO_Num.DO_Num;
			MEMWRITE1(tmp_short);
			for (int i = 0; i < base->IO_Num.DO_Num; i++)
			{
				tmp_short = base->Out.DO_PinSta[i];
				MEMWRITE1(tmp_short);
				tmp_short = base->Out.DO[i];
				MEMWRITE1(tmp_short);
			}

			BCNum[0]++;
		}
	}
	return _iLen;

#undef MEMWRITE1
}


//************************************
// Method:    	BCSAMAPARA					广播SAMA模块参数函数
// Programmer:  lww
// Time:		2019/2/16
// Returns:   	int							成功：返回打包字节个数；失败：返回0
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						广播SAMA参数的模块的ID号
// Parameter: 	void * * Data				广播SAMA参数的数据包的指针的指针
// Parameter: 	short * BCNum				广播SAMA参数的模块数量的计数变量的指针
//************************************
int BCSAMAPARA(List_Tab_t* arg, unsigned int ID, void** Data, short *BCNum)
{
#define MEMWRITE1(name)	MEMWRITE(name, Data[0])

	int _iLen = 0;

	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);

	if (base != NULL)
	{
		
		if (SAMA_PageBCFlag[base->PageNum - 1])
		{
			MEMWRITE1(base->List_Base.ID);				//< duan0930修改
			//< 广播私有参数（无参数需要广播的模块直接将BCPara函数设置为NULL即可）
			if (((Model_List_Func_t*)(arg->List_Func))->BCPara != NULL)
			{
				//< MEMWRITE1(base->List_Base.ID);			duan0930 修改
				_iLen += (((Model_List_Func_t*)(arg->List_Func))->BCPara(base, Data));
			}
			BCNum[0]++;
		}
	}
	return _iLen;

#undef MEMWRITE1
}


//************************************
// Method:    	OnlineChgPar				在线修改SAMA参数
// Programmer:  lww
// Time:		2018/11/16
// Returns:   	List_Info_e					链表操作状态（LIST_OK：操作成功；LIST_IDNON：该ID号模块不存在；LIST_MEMFAIL：内存操作失败）
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
// Parameter: 	void * Data					修改后的模块参数
// Parameter: 	int Data_Size				模块参数区字节数
//************************************
List_Info_e OnlineChgPar(List_Tab_t *arg, unsigned int ID, unsigned int Model_Type, void* Data, int Data_Size)
{
#define MEMREAD1(name)	MEMREAD(name, Data)

	int i;
	int _iLen = 0;
	float tmp_float;
	bool tmp_bool;

	Model_Base_t* _base = (Model_Base_t*)SearchId((List_Base_t*)arg->ppData[0], ID);
	if (_base != NULL)
	{
		//< 修改SAMA文件
		if (Open2Write(SAMA_FILE_PATH, _base->File_Read_Offset, Data, Data_Size) == false)
			printf("修改SAMA文件失败\r\n");

		//< 修改相关参数
		//< 给模块的引脚赋值
		for (i = 0; i < _base->IO_Num.AI_Num; i++)
		{
			if (_base->In.AI_Pin_ID[i] <= 0)
			{
				//< 无连接关系的引脚在此进行处理
				MEMREAD1(_base->In.AI[i][0]);
			}
			else
			{
				//< 有连接关系的引脚在setlink中会进行处理，在此处跳过读取值
				MEMREAD1(tmp_float);
			}
		}
		for (i = 0; i < _base->IO_Num.DI_Num; i++)
		{
			if (_base->In.DI_Pin_ID[i] <= 0)
			{
				//< 无连接关系的引脚在此进行处理
				MEMREAD1((_base->In.DI[i])[0]);
			}
			else
			{
				//< 有连接关系的引脚在setlink中会进行处理，在此处跳过读取值
				MEMREAD1(tmp_bool);
			}
		}
		
		if (Model_Type == TYP_USERDEF_UP)
		{
			for (i = 0; i < sizeof(_base->UserDef_Mod_Info.Mod_Name); i++)
			{
				MEMREAD1(_base->UserDef_Mod_Info.Mod_Name[i]);		//< .so库名
			}

			MEMREAD1(_base->UserDef_Mod_Info.UserDef_Mod_Type);		//< 自定义模块类型-  0-C语言动态链接库  1-python
			//< 读取模块中间参数的数量
			MEMREAD1(((USERDEF_T*)_base)->Sta.DigitalSta_Num);		//< 数字量中间参数数量
			MEMREAD1(((USERDEF_T*)_base)->Sta.AnalogSta_Num);		//< 模拟量中间参数数量

		}

		//< 给模块的可调参数赋值
		if (((Model_List_Func_t*)(arg->List_Func))->ChangePar != NULL)
		{
			_iLen += (((Model_List_Func_t*)(arg->List_Func))->ChangePar(_base, &Data));
		}

		if (_iLen == Data_Size)
			return LIST_OK;
		else
			return LIST_MEMFAIL;
	}
	return LIST_IDNON;

#undef MEMREAD1
}


//************************************
// Method:    	MODEL_CMD_DEAL				与SAMA模块相关的命令字处理
// Programmer:  lww
// Time:		2019/1/20
// Returns:   	List_Info_e					链表操作状态（LIST_OK：操作成功；LIST_IDNON：该ID号模块不存在）
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
// Parameter: 	void * Data					数据区指针
// Parameter: 	char * CMD					命令字
//************************************
List_Info_e MODEL_CMD_DEAL(List_Tab_t *arg, unsigned int ID, void* Data, const char* CMD)
{
	Model_Base_t* _base = (Model_Base_t*)SearchId((List_Base_t*)arg->ppData[0], ID);
	if (_base != NULL)
	{
		if (((Model_List_Func_t*)(arg->List_Func))->Model_CMD_Deal != NULL)
		{
			((Model_List_Func_t*)(arg->List_Func))->Model_CMD_Deal(_base, Data, CMD);
			return LIST_OK;
		}	
	}
	return LIST_IDNON;
}


//************************************
// Method:    	HoldSta						引脚状态变为保持
// Programmer:  lww
// Time:		2019/1/4
// Returns:   	List_Info_e					链表操作状态（LIST_OK：操作成功；LIST_IDNON：该ID号模块不存在）
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
// Parameter: 	bool type					0-模拟量；1-数字量
// Parameter: 	int IOIndex					引脚号
//************************************
List_Info_e HoldSta(List_Tab_t *arg, unsigned int ID, bool type, int IOIndex)
{
	int i = 0;
	Card_Base_t* SamaIOCard_pt = NULL;
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)arg->ppData[0], ID);
	if (base != NULL)
	{
		if (type == false && IOIndex < base->IO_Num.AO_Num)		//< 模拟量
		{
			base->Out.AO_PinSta[IOIndex] = IO_HOLD;
			base->Out.AO[IOIndex] = base->Out.Last_AO[IOIndex];
			if ((SamaIOCard_pt = (Card_Base_t*)ModelGetSamaIO(ID, IOIndex, &i)) != NULL)
			{
				AV_Write(&(SamaIOCard_pt->AOChannel[i]), 0, TURN_HOLD);
			}
			return LIST_OK;
		}
		else if (type == true && IOIndex < base->IO_Num.AO_Num + base->IO_Num.DO_Num && IOIndex >= base->IO_Num.AO_Num)	//< 数字量
		{
			base->Out.DO_PinSta[IOIndex - base->IO_Num.AO_Num] = IO_HOLD;
			base->Out.DO[IOIndex - base->IO_Num.AO_Num] = base->Out.Last_DO[IOIndex - base->IO_Num.AO_Num];
			
			if ((SamaIOCard_pt = (Card_Base_t*)ModelGetSamaIO(ID, IOIndex, &i)) != NULL)
			{
				DV_Write(&(SamaIOCard_pt->DOChannel[i]), false, TURN_HOLD);
			}

			return LIST_OK;
		}
	}
	return LIST_IDNON;
}


//************************************
// Method:    	ForceSta					引脚状态变为强制
// Programmer:  lww
// Time:		2019/1/4
// Returns:   	List_Info_e					链表操作状态（LIST_OK：操作成功；LIST_IDNON：该ID号模块不存在）
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
// Parameter: 	bool type					0-模拟量；1-数字量
// Parameter: 	int IOIndex					引脚号
// Parameter: 	void * Data					强制为的数据
//************************************
List_Info_e ForceSta(List_Tab_t *arg, unsigned int ID, bool type, int IOIndex, void *Data)
{
	int i = 0;
	Card_Base_t* SamaIOCard_pt = NULL;
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)arg->ppData[0], ID);
	if (base != NULL)
	{
		if (type == false && IOIndex < base->IO_Num.AO_Num)		//< 模拟量
		{
			base->Out.AO_PinSta[IOIndex] = IO_FORCE;
			base->Out.AO[IOIndex] = *((float*)Data);
			base->Out.Last_AO[IOIndex] = base->Out.AO[IOIndex];

			if ((SamaIOCard_pt =(Card_Base_t*) ModelGetSamaIO(ID,IOIndex,&i)) != NULL)
			{
				AV_Write(&(SamaIOCard_pt->AOChannel[i]), *((float*)Data), TURN_FORCE);
			}
			return LIST_OK;
		}
		else if (type == true && IOIndex < base->IO_Num.AO_Num + base->IO_Num.DO_Num && IOIndex >= base->IO_Num.AO_Num)	//< 数字量
		{
			base->Out.DO_PinSta[IOIndex - base->IO_Num.AO_Num] = IO_FORCE;
			base->Out.DO[IOIndex - base->IO_Num.AO_Num] = (bool)*((float*)Data);			//< duan 上位下发的值是float类型 
			base->Out.Last_DO[IOIndex - base->IO_Num.AO_Num] = base->Out.DO[IOIndex - base->IO_Num.AO_Num];

			if ((SamaIOCard_pt = (Card_Base_t*)ModelGetSamaIO(ID, IOIndex, &i)) != NULL)
			{
				DV_Write(&(SamaIOCard_pt->DOChannel[i]), (bool)*((float*)Data), TURN_FORCE);
			}
			return LIST_OK;
		}
	}
	return LIST_IDNON;
}


//************************************
// Method:    	NormalSta					引脚状态变为正常
// Programmer:  lww
// Time:		2019/1/4
// Returns:   	List_Info_e					链表操作状态（LIST_OK：操作成功；LIST_IDNON：该ID号模块不存在）
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
// Parameter: 	bool type					0-模拟量；1-数字量
// Parameter: 	int IOIndex					引脚号
//************************************
List_Info_e NormalSta(List_Tab_t *arg, unsigned int ID, bool type, int IOIndex)
{
	int i = 0;
	Card_Base_t* SamaIOCard_pt = NULL;
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)arg->ppData[0], ID);
	if (base != NULL)
	{
		if (type == false && IOIndex < base->IO_Num.AO_Num)		//< 模拟量
		{
 			base->Out.AO_PinSta[IOIndex] = IO_NORMAL;

			if ((SamaIOCard_pt = (Card_Base_t*)ModelGetSamaIO(ID, IOIndex, &i)) != NULL)
				AV_Write(&(SamaIOCard_pt->AOChannel[i]), 0, TURN_NORMAL);
			
			return LIST_OK;
		}
		else if (type == true && IOIndex < base->IO_Num.AO_Num + base->IO_Num.DO_Num && IOIndex >= base->IO_Num.AO_Num)	//< 数字量
		{
			base->Out.DO_PinSta[IOIndex - base->IO_Num.AO_Num] = IO_NORMAL;

			if ((SamaIOCard_pt = (Card_Base_t*)ModelGetSamaIO(ID, IOIndex, &i)) != NULL)
				DV_Write(&(SamaIOCard_pt->DOChannel[i]), false, TURN_NORMAL);

			return LIST_OK;
		}
	}
	return LIST_IDNON;
}


//************************************
// Method:    	BAKSAMA						主站向从站备份
// Programmer:  lww
// Time:		2019/2/16
// Returns:   	int							成功：返回打包字节个数；失败：返回0
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						备份模块的ID号
// Parameter: 	void * * Data				备份数据包指针的指针
// Parameter: 	short * BakNum				已经备份模块数量计数值的指针
//************************************
int BAKSAMA(List_Tab_t* arg, unsigned int ID, void** Data, short* BakNum)
{
#define MEMWRITE1(name)	MEMWRITE(name, Data[0])
	int _iLen = 0;
	int i;

	if ((((Model_List_Par_t*)(arg->List_Par))->Bak_Mode) != BAK_NON)
	{
		Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);	//由(Model_Base_t *)将链表头地址转换为模块指针类型
		if (base != NULL)
		{
			//< 备份公有参数
			MEMWRITE1(arg->Type);
			MEMWRITE1(base->List_Base.ID);

			MEMWRITE1(base->IO_Num.AO_Num);
			for (i = 0; i < base->IO_Num.AO_Num; i++)
			{
				MEMWRITE1(base->Out.AO_PinSta[i]);
				MEMWRITE1(base->Out.AO[i]);
				MEMWRITE1(base->Out.Last_AO[i]);
			}

			MEMWRITE1(base->IO_Num.DO_Num);
			for (i = 0; i < base->IO_Num.DO_Num; i++)
			{
				MEMWRITE1(base->Out.DO_PinSta[i]);
				MEMWRITE1(base->Out.DO[i]);
				MEMWRITE1(base->Out.Last_DO[i]);
			}

			MEMWRITE1(base->QuaTranSta);

			if ((((Model_List_Par_t*)(arg->List_Par))->Bak_Mode) == BAK_STA)
			{
				//< 备份中间运算参数
				if (((Model_List_Func_t*)(arg->List_Func))->BAKSta != NULL)
				{
					_iLen += (((Model_List_Func_t*)(arg->List_Func))->BAKSta(base, Data));
				}
			}

			BakNum[0]++;
		}
	}
	return _iLen;
#undef MEMWRITE1
}


//************************************
// Method:    	ANASAMA						从站解析主站备份来的数据
// Programmer:  lww
// Time:		2019/2/16
// Returns:   	int							成功：返回解析字节个数；失败：返回0
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						当前被解析模块的ID号
// Parameter: 	void * * Data				数据包指针的指针
//************************************
int ANASAMA(List_Tab_t* arg, unsigned int ID, void** Data)
{
#define MEMREAD1(var)	MEMREAD(var, Data[0])
	int _iLen = 0;
	float tmp_float;
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);//由(Model_Base_t *)将链表头地址转换为模块指针类型

	if (base != NULL)
	{
		//< 解析公有参数
		MEMREAD1(base->IO_Num.AO_Num);
		if ((((Model_List_Par_t*)(arg->List_Par))->Bak_Mode) == BAK_ATTEND) //用户自定义的模块是BAK_ATTEND这种模式
		{
			for (int i = 0; i < base->IO_Num.AO_Num; i++)
			{
				MEMREAD1(base->Out.AO_PinSta[i]);
				MEMREAD1(tmp_float);									//< duan0927 主站当前时刻AO值
				MEMREAD1(base->Out.Last_AO[i]);

				base->Out.Attend_Sta[i].Diff = tmp_float - base->Out.AO[i];
				base->Out.Attend_Sta[i].Delta = base->Out.Attend_Sta[i].Diff / ((Model_List_Par_t*)(arg->List_Par))->para->ATTEND_Amount;
				//< printf("Slave-Anasama-the diff is %f\r\n", base->Out.Attend_Sta[i].Diff);
			}
		}
		else
		{
			for (int i = 0; i < base->IO_Num.AO_Num; i++)
			{
				MEMREAD1(base->Out.AO_PinSta[i]);
				MEMREAD1(base->Out.AO[i]);
				MEMREAD1(base->Out.Last_AO[i]);
			}
		}


		MEMREAD1(base->IO_Num.DO_Num);
		for (int i = 0; i < base->IO_Num.DO_Num; i++)
		{
			MEMREAD1(base->Out.DO_PinSta[i]);
			MEMREAD1(base->Out.DO[i]);
			MEMREAD1(base->Out.Last_DO[i]);
		}

		MEMREAD1(base->QuaTranSta);

		if ((((Model_List_Par_t*)(arg->List_Par))->Bak_Mode) == BAK_STA)
		{
			//< 解析中间运算参数
			if (((Model_List_Func_t*)(arg->List_Func))->ANASta != NULL)
			{
				_iLen += (((Model_List_Func_t*)(arg->List_Func))->ANASta(base, Data));
			}
		}
	}

#undef MEMREAD1

	return _iLen;
}


//************************************
// Method:    	SetLink						建立模块间的连接关系
// Programmer:  lww
// Time:		2018/11/18
// Returns:   	List_Info_e					返回LIST_IDNON，代表ID不存在；返回LIST_OK，代表成功
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						SAMA模块的ID号
//************************************
List_Info_e SetLink(List_Tab_t* arg, unsigned int ID)
{
#define Base ((Model_Base_t*)base)
	int i;
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);

	if (base != NULL)
	{
		for (i = 0; i < Base->IO_Num.AI_Num; i++)
		{
			//< Setlink只处理有连接关系的引脚
			if (((Model_Base_t*)base)->In.AI_Pin_ID[i] > 0)
			{
				Model_Base_t* _base_connect = (Model_Base_t*)SearchId((List_Base_t *)(Model_List[Base->In.AI_Pin_Type[i]].ppData[0]), Base->In.AI_Pin_ID[i]);
				if (_base_connect != NULL)
				{
					Base->In.AI[i] = &(_base_connect->Out.AO[Base->In.AI_Pin_Num[i] - 1]);
					Base->In.AI_Pin_QualityInfo[i] = &_base_connect->Out.A_QualityInfo;
				}
				else
				{
					printf("Setlink Wrong\r\n");
				}
			}			
		}
		for (i = 0; i < Base->IO_Num.DI_Num; i++)
		{
			//< Setlink只处理有连接关系的引脚
			if (Base->In.DI_Pin_ID[i] > 0)
			{
				Model_Base_t* _base_connect = (Model_Base_t*)SearchId((List_Base_t *)(Model_List[Base->In.DI_Pin_Type[i]].ppData[0]), Base->In.DI_Pin_ID[i]);
				if (_base_connect != NULL)
				{
					Base->In.DI[i] = &(_base_connect->Out.DO[Base->In.DI_Pin_Num[i] - 1 - _base_connect->IO_Num.AO_Num]);				//< duan1009修改
					Base->In.DI_Pin_QualityInfo[i] = &_base_connect->Out.D_QualityInfo;
				}
				else
				{
					printf("Setlink Wrong\r\n");
				}
			}

		}
		return LIST_OK;
	}
	else
	{
		return LIST_IDNON;
	}

#undef Base
}


//************************************
// Method:    	SAMACALCU					SAMA模块运算函数
// Programmer:  lww
// Time:		2018/11/19
// Returns:   	List_Info_e					成功，返回LIST_OK，若访问的ID不存在，返回LIST_IDNON；若发生错误，返回LIST_MEMFAIL
// Parameter: 	List_Tab_t * arg			链表结构体的指针
// Parameter: 	int ID						模块ID号
//************************************
List_Info_e SAMACALCU(List_Tab_t* arg, unsigned int ID)
{
	int i;
	bool A_Qua = false;
	bool D_Qua = false;

	//< 初始化存放输入、输出引脚数值的数组
	bool* DI_ARRAY;
	bool* DO_ARRAY;
	float* AI_ARRAY;
	float* AO_ARRAY;
	
	Model_Base_t* base = (Model_Base_t*)SearchId((List_Base_t*)(arg->ppData[0]), ID);

	if (base == NULL)
		return LIST_IDNON;

	//< 确保各模块按照自身实际周期进行运算，实际周期按照设置的基准周期的倍数产生
	base->Period_Count++;
	if (base->Period_Count >= base->Model_Period)
	{
		base->Period_Count = 0;
		
		//< 质量传递信号处理
		if (base->QuaTranSta == QUA_NO_TRA_AD)
		{
			//< 模拟量与数字量均不进行质量传递
			base->Out.A_QualityInfo = false;
			base->Out.D_QualityInfo = false;
		}
		else
		{
			if (base->QuaTranSta == QUA_NO_TRA_A)
			{
				//< 模拟量不进行质量传递
				base->Out.A_QualityInfo = false;
			}
			else
			{
				/*对于具有输入引脚的模块来说，其质量传递状态由输入引脚所连接的模块的输出状态决定，
				故在此处作出处理判断，对于没有输入引脚的模块，即输入端的模块，其质量传递状态在其
				运算函数中根据模块具体情况进行具体处理*/
				if (base->IO_Num.AI_Num > 0)
				{
					//< 模拟量进行质量传递
					for (i = 0; i < base->IO_Num.AI_Num; i++)
					{
						if (base->In.AI_Pin_QualityInfo[i] != NULL)
						{
							A_Qua = A_Qua || *(base->In.AI_Pin_QualityInfo[i]);
						}
					}
					base->Out.A_QualityInfo = A_Qua;
				}
			}

			if (base->QuaTranSta == QUA_NO_TRA_D)
			{
				//< 数字量不进行质量传递
				base->Out.D_QualityInfo = false;
			}
			else
			{
				/*对于具有输入引脚的模块来说，其质量传递状态由输入引脚所连接的模块的输出状态决定，
				故在此处作出处理判断，对于没有输入引脚的模块，即输入端的模块，其质量传递状态在其
				运算函数中根据模块具体情况进行具体处理*/
				if (base->IO_Num.DI_Num > 0)
				{
					//< 数字量进行质量传递
					for (i = 0; i < base->IO_Num.DI_Num; i++)
					{
						if (base->In.DI_Pin_QualityInfo[i] != NULL)
						{
							D_Qua = D_Qua || *(base->In.DI_Pin_QualityInfo[i]);
						}
						base->Out.D_QualityInfo = D_Qua;
					}
				}
			}
		}

		//< 读取输入引脚值
		//< 开辟内存存放引脚数值
		DI_ARRAY = (bool*)calloc(base->IO_Num.DI_Num, sizeof(bool));
		DO_ARRAY = (bool*)calloc(base->IO_Num.DO_Num, sizeof(bool));
		AI_ARRAY = (float*)calloc(base->IO_Num.AI_Num, sizeof(float));
		AO_ARRAY = (float*)calloc(base->IO_Num.AO_Num, sizeof(float));

		//给输入引脚赋值
		for (i = 0; i < base->IO_Num.DI_Num; i++)
		{
			DI_ARRAY[i] = base->In.DI[i][0];
		}
		for (i = 0; i < base->IO_Num.AI_Num; i++)
		{
			AI_ARRAY[i] = base->In.AI[i][0];
		}

		//< 执行SAMA模块的运算程序
		if (((Model_List_Func_t*)(arg->List_Func))->CALCU != NULL)
		{

			if ((((Model_List_Func_t*)(arg->List_Func))->CALCU(base, base->dt, DI_ARRAY, DO_ARRAY, AI_ARRAY, AO_ARRAY)) == false)
			{
				printf("ERROR-The %d Model calculate is wrong\r\n", ID);
				//< 释放开辟的内存空间     duan20200513添加
				FREE_Pt(AO_ARRAY);
				FREE_Pt(AI_ARRAY);
				FREE_Pt(DO_ARRAY);
				FREE_Pt(DI_ARRAY);
				return LIST_MEMFAIL;
			}
				
		}

		//< SAMA运算输出值限幅
		for (i = 0; i < base->IO_Num.AO_Num; i++)
		{
			if (AO_ARRAY[i] < -1E8)
				AO_ARRAY[i] = -1E8;
			if (AO_ARRAY[i] > 1E8)
				AO_ARRAY[i] = 1E8;
		}

		//< 根据系统输出引脚状态决策系统输出值（强制、保持状态在各自的命令字处理程序中已经完成）
		for (i = 0; i < base->IO_Num.AO_Num; i++)
		{
			if (base->Out.AO_PinSta[i] == IO_NORMAL)
			{
				base->Out.Last_AO[i] = base->Out.AO[i];
				base->Out.AO[i] = AO_ARRAY[i];
				//< printf("the Calcu-AO is %f\r\n", base->Out.AO[i]);
			}
		}
		for (i = 0; i < base->IO_Num.DO_Num; i++)
		{
			if (base->Out.DO_PinSta[i] == IO_NORMAL)
			{
				base->Out.Last_DO[i] = base->Out.DO[i];
				base->Out.DO[i] = DO_ARRAY[i];
			}
		}

		//< 释放开辟的内存空间
		FREE_Pt(AO_ARRAY);
		FREE_Pt(AI_ARRAY);
		FREE_Pt(DO_ARRAY);
		FREE_Pt(DI_ARRAY);
	}	

	//< 当前站为主站且从站存在、且主从跟踪方式为衰减函数跟踪方式时，执行如下程序
	if (SYS_Role == Master_Twins_Role || SYS_Role == Master_Alone_Role)
	{
		if (((((Model_List_Par_t*)(arg->List_Par))->Bak_Mode) == BAK_ATTEND))
		{
			for (i = 0; i < base->IO_Num.AO_Num; i++)
			{
				if (base->Out.Attend_Sta[i].Diff != 0)
				{
					base->Out.Attend_Sta[i].Period_Count++;
					if (base->Out.Attend_Sta[i].Period_Count >= ((Model_List_Par_t*)(arg->List_Par))->para->ATTEND_Period)
					{
						base->Out.Attend_Sta[i].Period_Count = 0;
						base->Out.Attend_Sta[i].Diff = base->Out.Attend_Sta[i].Diff - base->Out.Attend_Sta[i].Delta;
						if (base->Out.Attend_Sta[i].Diff <= 0)
							base->Out.Attend_Sta[i].Diff = 0;
					}
					base->Out.AO[i] = base->Out.AO[i] + base->Out.Attend_Sta[i].Diff;
					//< printf("the diff-AO is %f\r\n", base->Out.Attend_Sta[i].Diff);
				}
			}
		}
	}

	
	return LIST_OK;
}


//************************************
// Method:    	Read_SAMA_File		读取SAMA文件
// Programmer:  lww
// Time:		2018/12/22
// Returns:   	bool				true：读取成功；false：读取失败
//************************************
bool Read_SAMA_File()
{
#define USERDEF_PATHNAME_LENGTH 100
#define WRONG_DEAL	{\
	printf("Read SAMA file failed, please check problem!\r\n");\
	free(Data_Start);\
	return false;\
}
#define MEMREAD1(name)	MEMREAD(name, Data)

	void* Data_Start = NULL;	//< 存放文件内容的内存的首地址
	void* Data = NULL;			//< 当前读写文件位置在内存中的地址
	int _iLen = 0;				//< 已经读取的字节个数
	int File_Size = 0;			//< 文件字节数
	int i, j, Model_Type;
	unsigned int Model_ID;
	SAMA_Model_IO_Num_t IO_PinNum;
	Model_Base_t* _base;
	bool temp_bool;
	float temp_float;
	int temp_int;
	void* handle;
	char UserDef_PathName[USERDEF_PATHNAME_LENGTH] = { 0 };//自定义模块
	

	printf("Begin to read SAMA file!\r\n");
	Model_Type_Map_Init();	//<上下位模块类型号映射关系初始化

	//< 打开文件并读取文件到内存中
	if (Open2Read(SAMA_FILE_PATH, &Data_Start, &Data, &File_Size) == false)
		return false;

	/****************************************/
	////////*python 自定义算法调用初始化*////////
	/****************************************/
	Py_Initialize();							//< 初始化Python，它会载入Python的内建模块并添加系统路径到模块搜索路径中。这个函数没有返回值，检查系统是否初始化成功需要使用Py_IsInitialized
	if (!Py_IsInitialized()) { WRONG_DEAL; }	//< 检查初始化是否成功
	//< 添加当前路径，把输入的字符串作为Python代码直接运行，返回0表示成功，-1表示有错，大多时候错误都是因为字符串中有语法错误
	PyRun_SimpleString("import sys");				//< duan0920 导入当前环境变量
	PyRun_SimpleString("print '---import sys---'");
	strcpy(UserDef_PathName, "sys.path.append('");
	strcat(UserDef_PathName, USERDEF_MODULE_FILE_PATH);
	strcat(UserDef_PathName, "')");
	PyRun_SimpleString(UserDef_PathName);
	/****************************************/
	///////*python 自定义算法调用初始化结束*//////
	/****************************************/

	/*******************解析文件信息**********************/
	
	//< 读取模块总数量
	MEMREAD1(Model_TotalNum);		

	//< 读取模块运算顺序
	for (i = 0; i < Model_TotalNum; i++)
	{
		MEMREAD1(Model_Calcu_ID[i]);
		MEMREAD1(temp_int);
		Model_Calcu_Type[i] = Model_Type_Map[temp_int];
	}

	//< 在链表中生成相应模块并向其赋值
	for (i = 0; i < Model_TotalNum; i++)
	{
		MEMREAD1(temp_int);
		Model_Type = Model_Type_Map[temp_int];
		MEMREAD1(Model_ID);
		memset(&IO_PinNum, 0, sizeof(SAMA_Model_IO_Num_t));
		MEMREAD1(IO_PinNum.AI_Num);
		MEMREAD1(IO_PinNum.DI_Num);
		MEMREAD1(IO_PinNum.AO_Num);
		MEMREAD1(IO_PinNum.DO_Num);

		//< 动态生成模块
		if ((AddModel(&Model_List[Model_Type], Model_ID, &IO_PinNum)) != LIST_OK)
			WRONG_DEAL;

		_base = (Model_Base_t*)SearchId(((List_Base_t*)Model_List[Model_Type].ppData[0]), Model_ID);

		if (_base != NULL)
		{
			//< 给模块的相关属性赋值
			MEMREAD1(_base->PageNum);
			MEMREAD1(_base->Model_Period);

			//if (Model_Type == TYP_DMC|| Model_Type == TYP_FFDMC)		
			//{								
			//	if (SYS_Role == Master_Twins_Role)						//< Shike20210311添加
			//	{
			//		ReadSAMAforFTPDMCFile(_base->List_Base.ID, Model_Type);
			//	}
			//}

			//< 给模块的连接关系赋值
			for (j = 0; j < IO_PinNum.AI_Num; j++)
			{
				MEMREAD1(_base->In.AI_Pin_ID[j]);
				MEMREAD1(temp_int);
				_base->In.AI_Pin_Type[j] = Model_Type_Map[temp_int];//AI_Pin_Type：连接的那个模块的类型
				MEMREAD1(_base->In.AI_Pin_Num[j]);
			}
			for (j = 0; j < IO_PinNum.DI_Num; j++)
			{
				MEMREAD1(_base->In.DI_Pin_ID[j]);
				MEMREAD1(temp_int);
				_base->In.DI_Pin_Type[j] = Model_Type_Map[temp_int];
				MEMREAD1(_base->In.DI_Pin_Num[j]);
			}

			//< 记录模块参数在SAMA文件中的指针偏移
			_base->File_Read_Offset = (long)((char*)Data - (char*)Data_Start);

			//< 给模块的引脚赋值
			for (j = 0; j < IO_PinNum.AI_Num; j++)
			{
				if (_base->In.AI_Pin_ID[j] <= 0)
				{
					//< 无连接关系的引脚在此进行处理
					_base->In.AI[j] = (float*)calloc(1, sizeof(float));
					MEMREAD1(_base->In.AI[j][0]); //此处赋值为0
					_base->In.AI_Pin_QualityInfo[j] = NULL;
				}
				else
				{
					//< 有连接关系的引脚在setlink中会进行处理，在此处跳过读取值
					MEMREAD1(temp_float);
				}
			}
			for (j = 0; j < IO_PinNum.DI_Num; j++)
			{
				if (_base->In.DI_Pin_ID[j] <= 0)
				{
					//< 无连接关系的引脚在此进行处理
					_base->In.DI[j] = (bool*)calloc(1, sizeof(bool));
					MEMREAD1((_base->In.DI[j])[0]);
					_base->In.DI_Pin_QualityInfo[j] = NULL;
				}
				else
				{
					//< 有连接关系的引脚在setlink中会进行处理，在此处跳过读取值
					MEMREAD1(temp_bool);
				}
			}

			//自定义模块处理
			if (Model_Type == TYP_USERDEF)
			{
				for (j = 0; j < sizeof(_base->UserDef_Mod_Info.Mod_Name); j++)
				{
					MEMREAD1(_base->UserDef_Mod_Info.Mod_Name[j]);		//< .so库名
				}
				MEMREAD1(_base->UserDef_Mod_Info.UserDef_Mod_Type);		//< 自定义模块类型-  0-C语言动态链接库  1-python
				//< 读取模块中间参数的数量
				MEMREAD1(((USERDEF_T*)_base)->Sta.DigitalSta_Num);		//< 数字量中间参数数量
				MEMREAD1(((USERDEF_T*)_base)->Sta.AnalogSta_Num);		//< 模拟量中间参数数量
				
				//< 根据Mod_Name组合出算法文件的路径
				memset(UserDef_PathName, 0, USERDEF_PATHNAME_LENGTH * sizeof(char));
				
				if (_base->UserDef_Mod_Info.UserDef_Mod_Type == USERDEF_TYP_C)
				{
					strcpy(UserDef_PathName, USERDEF_MODULE_FILE_PATH);
					strcat(UserDef_PathName, _base->UserDef_Mod_Info.Mod_Name);
					strcat(UserDef_PathName, ".so");

					//< 调用dlopen函数打开so文件，并且读取出里面的运算函数的指针，赋值给_base->UserDef_Mod_Info.Calcu_Method
					handle = NULL;
					handle = dlopen(UserDef_PathName, RTLD_LAZY);

					if (handle == NULL)
					{
						printf("USERDEF_dlopen-%s\r\n", dlerror());
						WRONG_DEAL;
					}

					_base->UserDef_Mod_Info.Calcu_Method = (bool(*)(bool*, bool*, float*, float*, float, bool*, float*, bool**, float**,char*))dlsym(handle, "Calcu_Method");

					if (dlerror() != NULL)
					{
						printf("SERDEF_dlsym-%s\r\n", dlerror());
						WRONG_DEAL;
					}
				}
				else if (_base->UserDef_Mod_Info.UserDef_Mod_Type == USERDEF_TYP_PY)
				{
					/****************************************/
					/////////////*python参数定义*/////////////
					/****************************************/
//					PyObject* pName = NULL;
					PyObject* pModule = NULL;
					PyObject* pDict = NULL;
					PyObject* pFunc = NULL;
					/****************************************/
					///////////*python参数定义结束*///////////
					/****************************************/

					/****************************************/
					//////////*python文件及函数调用*//////////
					/****************************************/

					/*pName = PyString_FromString(_base->UserDef_Mod_Info.Mod_Name);
					pModule = PyImport_Import(pName);	*/						//< duan0920 引入python模块
					pModule = PyImport_ImportModule("main");
					//pModule = PyImport_ImportModule(_base->UserDef_Mod_Info.Mod_Name);
					if (!pModule) 
					{
						//printf("can't find %s.py\r\n", _base->UserDef_Mod_Info.Mod_Name); 
						printf("can't find main.py\r\n");
						WRONG_DEAL;
					}
					pDict = PyModule_GetDict(pModule);							//< duan0920 获取模块字典属性，相当于python模块对象的_dict_属性，得到模块名称空间下的字典对象
					if (!pDict) { WRONG_DEAL; }
					char MainPYFunctionName[10] = "Calcu_";
					strcat(MainPYFunctionName, _base->UserDef_Mod_Info.Mod_Name);
					//pFunc = PyDict_GetItemString(pDict, "Calcu");// 找出函数名为Calcu的函数	//< duan0920 从字典属性中获取函数，函数名为Calcu
					pFunc = PyDict_GetItemString(pDict, MainPYFunctionName);
					if (!pFunc || !PyCallable_Check(pFunc)) 
					{
						printf("can't find function\r\n"); 
						WRONG_DEAL;
					}
					_base->UserDef_Mod_Info.pFunc = pFunc;
					/****************************************/
					////////*python文件及函数调用结束*////////
					/****************************************/
				}
			}

			//< 给模块的可调参数赋值
			if (((Model_List_Func_t*)(Model_List[Model_Type].List_Func))->ChangePar != NULL)
				_iLen += (((Model_List_Func_t*)(Model_List[Model_Type].List_Func))->ChangePar(_base, &Data));

			//< 初始化模块运算中间参数
			if (((Model_List_Func_t*)(Model_List[Model_Type].List_Func))->InitStaPar != NULL)
				((Model_List_Func_t*)(Model_List[Model_Type].List_Func))->InitStaPar(_base);

			//< 初始化模块运算周期（s）
			_base->dt = ((float)((_base->Model_Period)*SYS_BaseTime)) / 1000;

			//< 模块基本周期轮询次数初始化
			_base->Period_Count = 0;
		}
		else
			WRONG_DEAL;
	}
	
	//< 长度校验
	if (File_Size == _iLen)
		free(Data_Start);	//< 释放内存
	else
		WRONG_DEAL;

#undef MEMREAD1
#undef WRONG_DEAL
#undef USERDEF_PATHNAME_LENGTH

	printf("Read sama file success!\r\n");
	return true;
}


//************************************
// Method:    	tCalcu					SAMA运算线程
// Programmer:  lww
// Time:		2018/12/26
// Returns:   	void *
// Parameter: 	void * arg
//************************************
void *tCalcu(void* arg)
{
	struct timespec time;
	timer_t Calcu_Timer;
	int i, Model_ID, Model_Type;
//	struct timeval tv;
		

	//struct timespec time0, time1;

	//time0 = RealTime_Get();
	//time1 = RealTime_Get();

	printf("the Kernel_%s is %d\r\n", "tCalcu_ID", syscall(SYS_gettid));			//< duan20200610
	
	//< 建立模块间的连接关系
	for (i = 0; i < Model_TotalNum; i++) 
	{
		Model_ID = Model_Calcu_ID[i];
		Model_Type = Model_Calcu_Type[i];
		if (LIST_OK != SetLink(&Model_List[Model_Type], Model_ID))
		{
			printf("SetLink wrong!\r\n");
			while (1);
		}
	}
	printf("SetLink success\r\n");

	//< 建立软点与SAMA模块间的映射关系
	if (LIST_OK != SamaIOSetLink())
	{
		printf("SamaIO setLink wrong!\r\n");
		while (1);
	}
	else
		printf("SamaIO setlink success\r\n");

	//< 设置基准运算周期
	MS2TimeSpec(&time, SYS_BaseTime);
	//< 开启定时中断
	Timer_Create(&Calcu_Timer, CalcuSIG, &time);
	
	while (1)
	{
		//< 等待信号量释放进行运算操作
		/*MUTEX_LOCK(Calcu_Mutex, "Calcu_Mutex lock failed");*/
		SEM_WAIT(CalcuSemId, "CalcuSemId wait failed");
		//timespec Time1;
		//timespec Time2;
		//Time1 = RealTime_Get();
		
		if (SYS_Role == Master_Alone_Role || SYS_Role == Master_Twins_Role)
		{
			for (i = 0; i < Model_TotalNum; i++)
			{
				Model_ID = Model_Calcu_ID[i];
				Model_Type = Model_Calcu_Type[i];
				SAMACALCU(&Model_List[Model_Type], Model_ID);
				
			}
		}


		if (SYS_Role == Slave_Role)
		{
			for (i = 0; i < Model_TotalNum; i++)
			{
				Model_ID = Model_Calcu_ID[i];
				Model_Type = Model_Calcu_Type[i];
				SAMACALCU(&Model_List[Model_Type], Model_ID);
			}
		}

		//< 这两个变量为临时赋值，其具体的赋值位置和如何赋值等程序结构稍微健壮后再进行斟酌
		SYS_Status_Turn(Run_Status);
		SYS_BcORBak_Start = true;
		/*Time2 = RealTime_Get();
		int aaa = Dt_Calu(Time2, Time1);
		printf("DelayTime is %d!!!\n", aaa);*/
	}
}

//************************************
// Method:    	ModelGetSamaIO			根据SAMA模块ID号，引脚号，判断是否存在SAMAIO
// Programmer:  duan
// Time:		2019/05/24
// Returns:   	void *
// Parameter: 	unsigned int ID			模块ID
// Parameter: 	int IOIndex				引脚号
// Parameter: 	int* i					记录模块对应的SAMAIO通道位置
//************************************
void* ModelGetSamaIO(unsigned int ID, int IOIndex, int* i)
{

	unsigned int Model_ID = 0;			//< 模块ID号
	unsigned int Pt_ptr = 0;			//< 引脚号
	Card_Base_t* _base;
	_base = (Card_Base_t*)SearchId(((List_Base_t*)Card_List[TYP_SAMAIO].ppData[0]), SAMAIO_CARD_ID);
	if (_base != NULL)
	{
		if (_base->IO_Num.AO_Num > 0)
		{
			for (i[0] = 0; i[0] < _base->IO_Num.AO_Num; i[0]++)
			{
				SamaIOGetModel(_base, i[0], &Model_ID, &Pt_ptr,AO_CHA);
				if (ID == Model_ID && (Pt_ptr-1)==IOIndex)
					return _base;
			}

		}
		
		if (_base->IO_Num.DO_Num > 0)
		{
			for (i[0] = 0; i[0] < _base->IO_Num.DO_Num; i[0]++)
			{
				SamaIOGetModel(_base, i[0], &Model_ID, &Pt_ptr, DO_CHA);
				if (ID == Model_ID && (Pt_ptr - 1) == IOIndex)
					return _base;
			}
		}
		i[0] = 0;
		return NULL;
	}
	i[0] = 0;
	return NULL;

}
//************************************
// Method:    	ReadSAMAforFTPDMCFile	读SAMA文件时，如果检测到有DMC模块，需要把主站采样好的模型全部传到从站
// Programmer:  Shike
// Time:		2021/03/12
// Returns:   	bool
// Parameter: 	int ID					模块ID
// Parameter: 	int Type				模块类型
bool ReadSAMAforFTPDMCFile(int ID, int Type)
{
#define FTP_PORT	":21"
#define WRONG_DEAL(name)	{\
	if(name == 0){return false;}\
}
	char* Net;
	char Ip_Str[3] = { 0 };
	netbuf* ctrl;
	char tmp_char;
	/*if (SYS_Role == Master_Twins_Role && SYS_Status == Run_Status)*/
	tmp_char = (char)((IPTail_Num > MASTER_SLAVE_ID_DT) ? (IPTail_Num - MASTER_SLAVE_ID_DT) : (IPTail_Num + MASTER_SLAVE_ID_DT));//< Shike20210312 确定从站的IP末位
	sprintf(Ip_Str, "%d", ((int)tmp_char));		//< Shike20210312 从站的IP末位复制到IP地址字符串
	Net = (char*)calloc(strlen(NETA_NAME) + strlen(Ip_Str) + strlen(FTP_PORT), sizeof(char));
	strcpy(Net, NETA_NAME);
	strcat(Net, Ip_Str);
	strcat(Net, FTP_PORT);

	char fAddrAQA[] = { "/home/lww/mydmc/SN00000000/AQA1.dat" };//< ShiKe20200616 这是liunx文件地址 正斜杠
	int iCharSN = 0;
	int iAQACnt = 0;
	///	生成文件地址
	for (iAQACnt = 14; iAQACnt < 22; iAQACnt++) {
		iCharSN = ID >> (84 - iAQACnt * 4)/*(28+(iAQACnt-14)*4)*/ & 0x0F;
		fAddrAQA[iAQACnt + 4] = (iCharSN) > 9 ? '7' + iCharSN : '0' + iCharSN;
	}
	///	生成文件夹地址
	char Floderaddress[27];					//< 要保存模型文件的文件夹名，每个DMC模块的五个模型文件保存到一个文件夹
	for (int num = 0; num < 26; num++)
		Floderaddress[num] = fAddrAQA[num];
	Floderaddress[26] = '\0';
	if (access(Floderaddress, 0) == -1)	//< ShiKe20200616 确定文件/文件夹访问权限 当传入的是文件夹时只能判断文件夹是否存在，存在为0 不存在为-1
	{
		umask(0);//https://www.cnblogs.com/lovemdx/archive/2012/05/15/2501887.html 需要先设置掩码才行，否则Linux使用mkdir创建的文件夹权限和给函数的权限不对应
		if (-1 == mkdir(Floderaddress, S_IRWXU | S_IRWXG | S_IRWXO))				//< ShiKe20200721 linux最高权限0777代表了   ShiKe20200616 文件夹不存在，则创建文件夹
			printf("mkdir ERROR");
	}
	//printf("FTPDMCFile: %s Start backup\n", fAddrAQA);//< ShiKe20200715原文：FTPDMCFile: %s 开始备份\n
	WRONG_DEAL(FtpConnect(Net, &ctrl));
	WRONG_DEAL(FtpLogin(FTP_NAME, FTP_PASSWD, ctrl));
	FtpMkdir(Floderaddress, ctrl);

	if (Type == TYP_DMC)
	{
		for (int i = 1; i <= 5; i++)
		{
			char Addr30th_bit[1]; sprintf(Addr30th_bit, "%d",i);
			fAddrAQA[30] = Addr30th_bit[0];
			FILE* fpaa = NULL;
			fpaa = fopen(fAddrAQA, "rb");
			if (fpaa != NULL)
				WRONG_DEAL(FtpPut(fAddrAQA, fAddrAQA, FTPLIB_BINARY, ctrl));
		}
	}
	else if (Type == TYP_FFDMC)
	{
		for (int i = 1; i <= 6; i++)
		{
			char Addr30th_bit[1]; sprintf(Addr30th_bit, "%d", i);
			fAddrAQA[30] = Addr30th_bit[0];
			FILE* fpaa = NULL;
			fpaa = fopen(fAddrAQA, "rb");
			if (fpaa != NULL)
			{
				WRONG_DEAL(FtpPut(fAddrAQA, fAddrAQA, FTPLIB_BINARY, ctrl));
				fclose(fpaa);
			}
		}
		fAddrAQA[32] = 'c'; fAddrAQA[33] = 's'; fAddrAQA[34] = 'v';
		for (int i = 1; i <= 6; i++)
		{
			char Addr30th_bit[1]; sprintf(Addr30th_bit, "%d", i);
			fAddrAQA[30] = Addr30th_bit[0];
			FILE* fpaa = NULL;
			fpaa = fopen(fAddrAQA, "rb");
			if (fpaa != NULL)
			{
				WRONG_DEAL(FtpPut(fAddrAQA, fAddrAQA, FTPLIB_BINARY, ctrl));
				fclose(fpaa);
			}
		}
	}		
	WRONG_DEAL(FtpClose(ctrl));
	//printf("FTPDMCFile: %s Backup complete\n", fAddrAQA);//< ShiKe20200715原文：FTPDMCFile: %s 备份完成\n
	return true;
#undef FTP_PORT
#undef WRONG_DEAL(name)
}

